dart:core
庫中int.gcd
方法的用法介紹如下。
用法:
int gcd(
int other
)
返回此整數和 other
的最大公約數。
如果任一數字非零,則結果是除以 this
和 other
的數字上最大的整數。
最大公約數與順序無關,因此 x.gcd(y)
始終與 y.gcd(x)
相同。
對於任何整數 x
, x.gcd(x)
是 x.abs()
。
如果this
和other
都為零,則結果也為零。
例子:
print(4.gcd(2)); // 2
print(8.gcd(4)); // 4
print(10.gcd(12)); // 2
print(10.gcd(0)); // 10
print((-2).gcd(-3)); // 1
相關用法
- Dart int.fromEnvironment用法及代碼示例
- Dart int.toUnsigned用法及代碼示例
- Dart int.bitLength用法及代碼示例
- Dart int.operator_shift_left用法及代碼示例
- Dart int.parse用法及代碼示例
- Dart int.toRadixString用法及代碼示例
- Dart int.operator_bitwise_and用法及代碼示例
- Dart int.operator_bitwise_exclusive_or用法及代碼示例
- Dart int.tryParse用法及代碼示例
- Dart int.operator_triple_shift用法及代碼示例
- Dart int.operator_bitwise_or用法及代碼示例
- Dart int.operator_shift_right用法及代碼示例
- Dart int.toSigned用法及代碼示例
- Dart identityHashCode用法及代碼示例
- Dart identical用法及代碼示例
- Dart MapMixin.containsKey用法及代碼示例
- Dart Iterator用法及代碼示例
- Dart AttributeClassSet.intersection用法及代碼示例
- Dart num.sign用法及代碼示例
- Dart TransformList.last用法及代碼示例
- Dart FileList.first用法及代碼示例
- Dart CanvasRenderingContext2D.drawImageScaledFromSource用法及代碼示例
- Dart FileList.length用法及代碼示例
- Dart Iterable.takeWhile用法及代碼示例
- Dart LinkedHashMap用法及代碼示例
注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 gcd method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。