In my last post I talked about finding the number of zeroes at the end of , and I said that there was room for improvement. I thought about it a little bit and found a couple things to speed it up.
The first has to do with the relationship between the quantity of fives and the quantity of twos. The lower quantity in the prime factorization of is how many zeroes it will have at the end. If I would have thought a little more about it though I would have seen that counting the twos is pointless in this situation.
Even the prime factorization of has the information in there: there will always be more twos than fives. Counting from 1 to 10:
- Multiples of 2: 2, 4, 6, 8, 10
- Multiples of 5: 5, 10
This means that all we really need to keep track of is the quantity of fives in the prime factorization of . Which leads to the second optimization: we only need to get the prime factorization of multiples of five.