- Published on
Trailing Zeros in Factorial
- Authors
- Name
- Richard Feng
- @richard____feng
For any positive integer , the factorial of , denoted as , is defined as
is defined as 1, i.e. , though it looks unintutive. However, we can write this formula recursively as follows:
Now, for , we have and this implies that .
The table below shows the values of the factorial for the integers 1 to 16.
1 | 1 |
2 | 2 |
3 | 6 |
4 | 24 |
5 | 120 |
6 | 720 |
7 | 5040 |
8 | 40320 |
9 | 362880 |
10 | 3628800 |
11 | 39916800 |
12 | 479001600 |
13 | 6227020800 |
14 | 87178291200 |
15 | 1307674368000 |
16 | 20922789888000 |
Counting the Trailing Zeros
How do we find the number of trailing zeros in a factorial? For example, when is 5, has 1 trailing zero; when is 12, has 2 trailing zeros; when is 16, has 3 trailing zeros.
Given a positive integer number , how many trailing zeroes are in factorial?
Bonus: can you implement this in any programming language?