1012 最小公倍数LCM
输入2个正整数A,B,求A与B的最小公倍数。
Input
2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)
Output
输出A与B的最小公倍数。
Input示例
30 105
Output示例
210
一道纯数学题目,先求出最大共约数,再求最小公倍数。
代码如下:
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
def lcm(a, b):
return a//gcd(a,b) * b
while True:
try:
A,B = list(map(int, input().split()))
print(lcm(A, B))
except EOFError:
break