gcd function

int gcd(
  1. int a,
  2. int b
)

Returns the greatest common divisor of a and b. Uses the highly optimized Euclidean algorithm.

Implementation

int gcd(int a, int b) {
  a = a.abs();
  b = b.abs();
  while (b != 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}