python计算最大公约数和最小公倍数

a=4
b=2
def gcd(a,b):
       return a if b==0 else gcd(b,a%b)

def lcm(a,b):
   return a*b//gcd(a,b)    
print(gcd(a,b))#最大公约数
print(lcm(a,b))#最小公倍数   

猜你喜欢

转载自www.cnblogs.com/c-x-a/p/10023449.html