Python/ref math gcd
来自菜鸟教程
<languages />
Python math.gcd()方法
例
找到两个整数的最大公约数:
#Import math Library
import math
#find the the greatest
common divisor of the two integers
print (math.gcd(3, 6))
print (math.gcd(6,
12))
print (math.gcd(12, 36))
print (math.gcd(-12, -36))
print (math.gcd(5,
12))
print (math.gcd(10, 0))
print (math.gcd(0, 34))
print (math.gcd(0,
0))
定义和用法
The
math.gcd()
方法返回两个整数的最大公约数
int1
and
int2
.
GCD是最大的除数,可除以余数。
GCD也被称为最高公因子(HCF)。
Tip: gcd(0,0)返回0。
句法
math.gcd(int1, int2)
参数值
| 参数 | 描述 |
|---|---|
| int1 | 需要。找到GCD的第一个整数 |
| int2 | 需要。查找GCD的第二个整数 |
技术细节
| 返回值: | An
|
| Python版本: | 3.5 |