libra-gyf

求最大公约数&最小公倍数

#求最大公约数
def
hcf(x,y): if x>y: s = y else: s=y for i in range(1,s+1): if y%i ==0 and x %i ==0: hcf =i return hcf x = int(input("输入一个数: ")) y = int(input("输入另一个数: ")) print( x,"", y,"的最大公约数为", hcf(x,y))
#最小公倍数
def hcf(x,y): if x>y: s = y else: s=x for i in range(1,s+1): if y%i ==0 and x %i ==0: hcf =x*y/i return int(hcf) x = int(input("输入一个数: ")) y = int(input("输入另一个数: ")) print( x,"与", y,"的最大公约数为", hcf(x,y))

 

posted on 2019-12-28 18:01  libra-gyf  阅读(139)  评论(0编辑  收藏  举报

导航