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);