The english description of the algorithm is “find and multiply the largest power of every prime that is less than or equal to the maximum of the range”.

We’re basically saying that we don’t care what the actual numbers are for the lcm, we just care about the largest prime powers that fit in the range. And since multiplying two primes can’t make the number smaller, we know that if 2**5 won’t fit, neither will 2**5 times anything else. And if 2**2*3 fits, so will both 2**2 and 3. So basically if a composite exists in the range the largest prime power it can have is also in the range (since it has to be at least half as big).

This actually kind of works for ranges that don’t start with 1 too. If the power is in the range, you’re done. Otherwise you have to backtrack down through smaller powers until you find one that has a prime in (min .. max) / power.

]]>my @primes = (2,3,5,7,11,13,17,19);

[*] @primes.map({ $^prime ** log(20, $^prime).floor; }); ]]>

That really takes the wind out of the entire project, doesn’t it?

]]>