python计算最大公约数和最小公倍数
#!/usr/bin/env python‘’’求两个整数的最大公约数和最小公倍数,最大公约数和最小公倍数的乘积是两个整数的乘积‘’’#辗转相除法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...
·
#!/usr/bin/env python
‘’’
求两个整数的最大公约数和最小公倍数,最大公约数和最小公倍数的乘积是两个整数的乘积
‘’’
#辗转相除法
a=int(input(‘please enter 1st num:’))
b=int(input(‘please enter 2nd num:’))
s=a*b
while a%b !=0:
a,b=b,(a%b)
else:
print(b,‘is the maximum common divisor’)
print(s//b,‘is the least common multiple’)
更多推荐
所有评论(0)