If I have a list of positive natural numbers and a function to compute the LCM of 2 numbers, can I compute the LCM of all the numbers in the list using this simple algorithm (written in Python)?
calculate_lcm(numbers: list):
answer = numbers[0]
for index in range(1, len(numbers)):
answer = lcm(answer, numbers[index])
return answer
That is, assign the first number as the lcm. Then take the LCM of the current lcm with the second number and call that the LCM. Then take LCM with the current candidate LCM and the 3rd number and have a new candidate. Then take the LCM with the current candidate and fourth number, so on and so on.
Intuitively I think that's too simple and there must be a case where that breaks, but I can't find the case.