当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Dart BigInt.gcd用法及代码示例


dart:core 库中BigInt.gcd 方法的用法介绍如下。

用法:

BigInt gcd(
   BigInt other   
)

返回此大整数和 other 的最大公约数。

如果任一数字非零,则结果是除以 thisother 的数字上最大的整数。

最大公约数与顺序无关,因此 x.gcd(y) 始终与 y.gcd(x) 相同。

对于任何整数 xx.gcd(x)x.abs()

如果thisother 都为零,则结果也为零。

例子:

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

相关用法


注:本文由纯净天空筛选整理自dart.dev大神的英文原创作品 gcd method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。