题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
''' 2 12 14 6 7 2*6*7=84 4 12 16 3 4 4*3*4=48 2 12 16 2 6 8 3 4 ''' ''' # 遍历:数字越大,越耗时,超时 num=input().split() a=int(num[0]) b=int(num[1]) for i in range(1,a*b+1): if i%a==0 and i%b==0: print(i) break ''' # 按照数学求最小公倍数的过程求解,运行时间较短 num=list(map(int,input().split())) a=num[0] b=num[1] #print(num,a,b) comul=1 for i in range(2,min(num)+1): while a%i==0 and b%i==0: comul *= i a=a/i b=b/i comul=int(comul*a*b) print(comul)