gcd abstract method

BigInt gcd(
  1. BigInt other
)

Returns the greatest common divisor of this big integer and other.

If either number is non-zero, the result is the numerically greatest integer dividing both this and other.

The greatest common divisor is independent of the order, so x.gcd(y) is always the same as y.gcd(x).

For any integer x, x.gcd(x) is x.abs().

If both this and other is zero, the result is also zero.

Example:

print(BigInt.from(4).gcd(BigInt.from(2))); // 2
print(BigInt.from(8).gcd(BigInt.from(4))); // 4
print(BigInt.from(10).gcd(BigInt.from(12))); // 2
print(BigInt.from(10).gcd(BigInt.from(10))); // 10
print(BigInt.from(-2).gcd(BigInt.from(-3))); // 1

Implementation

BigInt gcd(BigInt other);