jackfrued/Python-Core-50-Courses

第6课最大公因数,最小公倍数有点小问题

heqiang233 opened this issue · 3 comments

没有考虑x,y的大小,建议修改一下
x = int(input('x = '))
y = int(input('y = '))
if x > y:
x, y = y, x
for factor in range(x, 0, -1):
if x % factor == 0 and y % factor == 0:
print(f'{x}和{y}的最大公约数是{factor}')
print(f'{x}和{y}的最小公倍数是{x * y // factor}')
break