Find the number of trailing zeros in $n!$.

997 Views Asked by At

Can anyone give me a generalized way to find the number of zeroes trailing at the end of $n!$ ?

1

There are 1 best solutions below

4
On BEST ANSWER

The number of zeroes at the end of $n!$ is

$$f(n) = \large \sum_{i=1}^{\log_5n} \lfloor\frac{n}{5^i}\rfloor$$

In simpler terms, it's basically the largest power of $5$ that divide $n!$.

Explanation: Okay. Well, a number is divisible by $10$ if it is divisible by both $5$ and $2$. The largest power of $10$ that divides it is simply the minimum of the largest power of $5$ that divides it or $2$ the largest power of $2$ that divides it. It is obvious that the power of $2$ dividing $n!$ is larger than the power of $5$ dividing $n!$. So, we find the largest power of $5$ that divides $n!$. Now what you might do is simply divide $n$ by $5$ which is incorrect. You see, there exist numbers like $25$ which are divisible by $5^2$. So, you have to count them again.

Then find $f(n!)$. You are done.