Gian Saß

Trailing Zeros of Factorials

· Gian Sass

Since I’m bored to hell in programming class, my teacher, who is also my physics teacher, gave me the task to find out the trailing zeros of100! and then forn! . I then began searching for patterns in factorials starting from1! to 10!. Interestingly,5! = 120 has one trailing zero and10! =3628800 has two trailing zeros. By induction you could determine the trailing zeros of factorials to be expressed by \lfloor \frac{n}{5} \rfloor, where\lfloor x \rfloor is the floor function.

But if you go down the pattern a bit further you find that25! =15511210043330985984000000 which has six zeros! The heck? This contradicts our idea. Let’s investigate a bit further.

In a factorial, the amount of fives getting multiplied adds a zero. For example10! = 1\times2\times3\times4\times5\times6\times7\times8\times9\times10 . If we take a look we see that there are two 5s hidden here,5 and10=5\times2 . But25! contains the factor25 which is5^2 ! So in that case, we find that there are six fives, because25=5\times5 .

With this additional information we can determine the number of trailing zeros of 25! to be \lfloor \frac{25}{5}\rfloor +\lfloor \frac{25}{5^2} \rfloor = 6

But we are not finished yet, there is a pattern here and we should be able to define it for anyn! .

Given a number n, the trailing zeros of n! is the sum of n divided by all of its prime factors of 5.

\big f(n) = \sum\limits_{i=1}^{k} \lfloor \frac{n}{5^i} \rfloor

wherek has to be chosen such that5^{k+1} > n .

For example let’s calculate the trailing zeros of100! . We find5^3 = 125 > 100 leaving us withf(100) = \lfloor \frac{100}{5}\rfloor +\lfloor \frac{100}{25}\rfloor = 24 .