Is there a C++ algorithm to calculate the least common multiple for multiple numbers, like lcm(3,6,12)
or lcm(5,7,9,12)
?
If you look at this page, you can see a fairly simple algorithm you could use. :-)
I'm not saying it's efficient or anything, mind, but it does conceptually scale to multiple numbers. You only need space for keeping track of your original numbers and a cloned set that you manipulate until you find the LCM.