gcd()函数Python
最大公约数或gcd是找到最大数的数学表达式,该数学数可以将必须找到gcd的两个数相除,结果余数为零。它具有许多数学应用程序。Python在math模块中具有内置的gcd函数,可用于此目的。
gcd()
它接受两个整数作为参数,并返回作为gcd值的整数。
语法
Syntax: gcd(x,y) Where x and y are positive integers.
gcd()的示例
在下面的示例中,我们打印出一对整数的gcd结果。
import math
print ("GCD of 75 and 30 is ",math.gcd(75, 30))
print ("GCD of 0 and 12 is ",math.gcd(0, 12))
print ("GCD of 0 and 0 is ",math.gcd(0, 0))
print ("GCD of -24 and -18 is ",math.gcd(-24, -18))输出结果
运行上面的代码给我们以下结果-
GCD of 75 and 30 is 15 GCD of 0 and 12 is 12 GCD of 0 and 0 is 0 GCD of -24 and -18 is 6
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便