Factorial question: number of trailing zeroes in 125!

Well, we know that to have a zero at the end then $10$ must be a factor, which means $5$ and $2$ must be factors. However, every other factor is even, so there are far more factors of $2$ than $5$ - As such, we have to count the number of factors divisible by $5$. The number of factors divisible by $5$ less than or equal to $125$ is $25$ (we just do $\frac{125}{5}$), so the answer appears to be $25$, but then we remember that $25 = 5\cdot5$, so we must count double for each factor divisible by $25$, of which there are $5$; accordingly, our new answer is $30$. BUT WAIT... $125 = 5^3$, so we have to count it too, giving us a final answer of $31$


The formula explaining above: $$\text{Number of zeros in }n!=\left[ \frac {n}{5} \right]+\left[ \frac {n}{5^2} \right]+\ldots $$ where [.] denotes the greatest integer function.


Note that if there is at least one zero after the last non-zero digit of $125!$, then $125!$ is divisible by $10$. Likewise, if there are two, then $125!$ is divisible by $100$, etc.. Thus, we need to check how many times $125!$ is divisible by $10$.

So, we count the multiples of $5^1$, $5^2$, and $5^3 = 125$, in $125!$. It is easy to see that there are $25 = 125/5$ factors divisible by $5^1 = 5$, less than $125$. Similarly, there are $ 5 = 125/25 $ factors divisible by $5^2 = 25$ in $125$. And finally, there is $1 = 125/125$ factors divisible by $5^3 = 125$. Thus, by the sum rule, there are $25 + 5 + 1 = 31$ such factors. But, this counts the number of times $125!$ is divisible by $10$, since $10 = 5 \times 2$, and there is a $2$ in the prime decomposition of $125!$.