Python的内置函数math.gcd()
用于计算两个整数的最大公约数(greatest common divisor,GCD)。该函数接受两个参数,这两个参数都应该是整数。
参数限制如下:
TypeError
。ValueError
。以下是一个使用math.gcd()
函数的示例:
import math
a = 56
b = 98
result = math.gcd(a, b)
print(f"The GCD of {a} and {b} is {result}")
输出结果:
The GCD of 56 and 98 is 14
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>