题解 | #求最小公倍数#
求最小公倍数
http://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
'''
for循环的条件“for in range(2,min(m,n)+1):”里的m,n不会受到循环内容“m=m//i n=n//i”影响
例如:
w=[1,2]
for i in w:
w=[3,4]
print(i)
>>
1
思路借用一下大佬的图:
'''
m, n = list(map(int, input().split( )))
T=1
for i in range(2,min(m,n)+1):
while m%i==0 and n%i==0: ##重点,直到2不行了在换3...
T=T*i
m=m//i
n=n//i
print(T*m*n)
for循环的条件“for in range(2,min(m,n)+1):”里的m,n不会受到循环内容“m=m//i n=n//i”影响
例如:
w=[1,2]
for i in w:
w=[3,4]
print(i)
>>
1
2
'''
m, n = list(map(int, input().split( )))
T=1
for i in range(2,min(m,n)+1):
while m%i==0 and n%i==0: ##重点,直到2不行了在换3...
T=T*i
m=m//i
n=n//i
print(T*m*n)
【牛客站内】华为机试题—简单 文章被收录于专栏
【牛客站内】华为机试题练习记录