greatestCommonDivisorOfManyBig function

BigInt greatestCommonDivisorOfManyBig (List<BigInt> integers)

Returns the greatest common divisor (gcd) of many BigInt using Euclid's algorithm.

Implementation

BigInt greatestCommonDivisorOfManyBig(List<BigInt> integers) {
  if (null == integers) {
    throw ArgumentError.notNull('integers');
  }

  if (integers.length == 0) {
    return BigInt.zero;
  }

  var gcd = integers[0].abs();

  for (var i = 1; (i < integers.length) && (gcd > BigInt.one); i++) {
    gcd = greatestCommonDivisorBig(gcd, integers[i]);
  }

  return gcd;
}