def getLCM(a, b):
c, d = max(a, b), min(a, b)
while c != d:
temp = c - d
c, d = max(temp, d), min(temp, d)
return a * b // c
def nlcm(num):
temp = 1
while len(num) != 0:
temp = getLCM(temp, num[-1])
num.pop()
return temp
print(nlcm([2,6,8,14,5]));
我需要“快速”回答这个问题。在测试用例中,我的代码很慢。