jackfrued / Python-Core-50-Courses

Python语言基础50课

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

heqiang233 opened this issue · 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

commented