dart:core
庫中BigInt.gcd
方法的用法介紹如下。
用法:
BigInt 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
相關用法
- Dart BigInt.toRadixString用法及代碼示例
- Dart BigInt.operator_divide用法及代碼示例
- Dart BigInt.from用法及代碼示例
- Dart BigInt.isValidInt用法及代碼示例
- Dart BigInt.toDouble用法及代碼示例
- Dart BigInt.parse用法及代碼示例
- Dart BigInt.bitLength用法及代碼示例
- Dart BigInt.operator_truncate_divide用法及代碼示例
- Dart BigInt.tryParse用法及代碼示例
- Dart BigInt.compareTo用法及代碼示例
- Dart BigInt.remainder用法及代碼示例
- Dart BigInt.toInt用法及代碼示例
- Dart BigInt.operator_modulo用法及代碼示例
- Dart BigInt.toUnsigned用法及代碼示例
- Dart BigInt.toString用法及代碼示例
- Dart BigInt.pow用法及代碼示例
- Dart BigInt.toSigned用法及代碼示例
- Dart BigInt用法及代碼示例
- Dart Base64Encoder用法及代碼示例
- Dart ByteData.view用法及代碼示例
- Dart ByteData用法及代碼示例
- Dart Base64Decoder用法及代碼示例
- Dart MapMixin.containsKey用法及代碼示例
- Dart Iterator用法及代碼示例
- Dart AttributeClassSet.intersection用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 gcd method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。