gcd function

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

Calculate the greatest common divisor (GCD) of a and b

Implementation

(BigInt a, BigInt b) gcd(BigInt a, BigInt b) {
  if (a == BigInt.zero ||
      b == BigInt.zero ||
      a == BigInt.one ||
      b == BigInt.one) {
    return (a, b);
  }

  final gcd = a.gcd(b);
  a = a ~/ gcd;
  b = b ~/ gcd;
  return (a, b);
}