public static function gcdMultiple(BigInteger $a, BigInteger ...$n) : BigInteger { $result = $a; foreach ($n as $next) { $result = $result->gcd($next); if ($result->isEqualTo(1)) { return $result; } } return $result; }