python里如何求两个数的最小公倍数?
1个回答
利用公式$lcm(a,b)=ab/gcd(a,b)$
from math import gcd
def lcm(a,b):
prod = abs(a * b)
gcd_ab = gcd(a,b)
if gcd_ab == 0:
return 0
return int(prod / gcd_ab)
多谢!
-
魏哲
2018-05-10 22:08