A Consideration on Factors and Algorithms

November 8, 2011

The locker problem asked as an addendum, which of the 100 lockers will be toggled the most and the least?

Having the established foundation based on the number of factors, it is easy to see that locker 1 will have the least toggles, exactly 1. Every other locker will have at least two toggles.

Then which one will have the most - the one whose locker number has the most unique factors.

To determine the number with the most number of unique factors in a given range, it is necessary to generate such a number so that it is divisible by (1,2,3,4,5...) as many of the low integers as the given range allows. This generation pattern follows an interesting sequence: 1*2*3*2*5*1*7*2*3*1*11*1*... As one may see, it contains only prime numbers but the interesting feature is that it multiplies the previous result by only the prime that it is missing in order to be divisible by the next integer.

An inefficient version of the above algorithm would be to calculate the factorial: 1*2*3*4*5*6..., however in order to obtain a number divisible by 1,2,3,4,5, and 6, it is only necessary to multiply 1*2*3*2*5*1 - much more efficient packing, and this is the reason why this pattern generates the smallest number that contains the most factors.

If range is not an issue but the number of prime factors is (that is, minimize ratio of prime factors to total unique factors), one would preferentially choose all unique prime factors as that will yield 2^n possible factors. However, using this algorithm and applying a range limit to it will not be efficient since the aforementioned algorithm allows use of repeating prime factors to achieve the best number size reduction to fit a particular range. For instance if one would like to know the number with the most factors that is less than 1000, the unique primes approach would give 1*2*3*5*7=210, while the most-factors algorithm will give 1*2*3*2*5*1*7*2=840, clearly a better answer for the problem.

Yet neither algorithm is ideal, and other factors must be taken into account...

Looks like a definitive algorithm is to use the initial pattern, 1*2*3*2*5*7*2*3*11... and truncate it so that it is just less than the maximum allowed range. Now divide the maximum allowed range by the number obtained from the truncated pattern, and floor the result. Next find a prime factorization such that it is closest possible less than or equal to the division result.

For instance, what is the number with most unique composite and prime factors that is less than 2000? How many factors does it have?

Using the pattern 1*2*3*2*5*1*7*2*3=2520 which is above the maximum range, then 1*2*3*2*5*1*7*2=840. Now floor(2000/840)=2 so the number we are looking for is 840*2=1680. Performing a factorization on the number, we obtain a total of 40 factors. It can be computationally proven that no other number less than 2000 has 40 unique factors.