辗转相除法计算最大公约数和最小公倍数
"""
欧几里得 = 辗转相处
最大公约数等于两数辗转相处之后的最终余数
比如10和25,25除以10商2余5,那么10和25的最大公约数,等同于10和5的最大公约数。
二者关系:两个数之积=最小公倍数*最大公约数
"""
a=int(input('please enter 1st num:'))
b=int(input('please enter 2nd num:'))s=a*bwhile a%b!=0: a,b=b,(a%b) else: print(b,'is the maximum common divisor') print(s//b,'is the least common multiple')#运行结果please enter 1st num:10please enter 2nd num:155 is the Maximum common divisor30 is the Least common multiple
浙公网安备 33010602011771号