This question already has an answer here:


How many trailing zeroes are there in $52!$ ?

My thoughts

I believe I correctly solved it, but I'm not happy with the scalability of my method.

I figure the number of trailing zeroes is equal to the number of times $52!$ is divisible by 10. I wrote out every integer from 1-52 that is divisible by 2 or 5. The idea being that the number of 2 AND 5-factors equals the number of 10-factors.

I quickly noted that the number of 2-factors is greater than the number of 5-factors, so I figured finding the number of 5-factors will do. There were 12.

I'm not very happy with this, because if they now ask me to do the same for $152!$, I'll have to tell them to shove it. I'm not doing this again.


Is there a better way to do this? Perhaps a method that scales better?


marked as duplicate by Jyrki Lahtonen Aug 27 '17 at 16:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ You want Legendre's formula and can search the site for many similar questions. $\endgroup$ – Ross Millikan Aug 27 '17 at 16:36
  • $\begingroup$ Your method looks good and should be quick now you have the basics. Undertaking the same task for $152!$ should rapidly give you some insight into how to solve the problem quicker. Look out for $125$. $\endgroup$ – Joffan Aug 27 '17 at 16:39
  • $\begingroup$ Perhaps a better redirect for this question (and not a question that is closed, either): math.stackexchange.com/questions/141196/… $\endgroup$ – Joffan Aug 27 '17 at 16:49

You get your $12$ by counting $\left\lfloor\frac{52}{5}\right\rfloor+\left\lfloor\frac{52}{25}\right\rfloor$. This counts each multiple of $5$ in the product $52!$, then adds on a count for each multiple of $25$. This can generalize to $152$. You'll need to go up to $125$ with divisors.

In general, the number of trailing $0$s in $n!$ will be $$\sum_{k=1}^{\infty}\left\lfloor\frac{n}{5^k}\right\rfloor$$ where for any $n$, only the first few terms in that infinite sum will be nonzero.


Not the answer you're looking for? Browse other questions tagged or ask your own question.