有没有大哥会,教教我 好难

有没有大哥会,教教我 好难

最大公约数用辗转相除法gcd,你上网搜索一下,很简单

# 辗转相除法求最大公约数和最小公倍数
a, b = map(int, input("输入两个数").split())
a1, b1 = a, b
res = a1 % b1
while res != 0:
    a1 = b1
    b1 = res
    res = a1 % b1
print("最大公约数为:" + str(b1) + "  最小公倍数为:" + str(a*b/b1))

 

# 求最大公倍数和最小公约数
a, b = map(int, input("输入两个数").split())
m=[]
if a>b:
    smaller=b
else:
    smaller=a
for i in range(1,smaller+1):
    if (a%i==0) and (b%i==0):
        m.append(i)
    continue
n=m[-1]
print("最大公约数为:" + str(n) + "  最小公倍数为:" + str(a*b//n))