gcd抽象方法
- BigInt other
返回当前大整数与other的最大公约数。
如果任一数字非零,则结果为可以同时整除this和other的最大整数。
最大公约数与顺序无关,因此x.gcd(y)始终与y.gcd(x)相同。
对于任何整数x,x.gcd(x)等于x.abs()。
如果this和other都为零,则结果也为零。
示例
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
实现
BigInt gcd(BigInt other);