# 100 Factorial

### From Mycoted

One for the mathematicians this week, with thanks to Paul Kellet for sending it in.

How many zeros are there at the end of 100! (factorial)?

Answer | |
---|---|

24
The trick here is not to calculate 100! on your calculator (which only gives you ten digits of accuracy), but to figure out how high a power of 10 goes into 100! evenly. For every trailing zero, there is a power of 10 that divides 100! evenly. In order to do that, since 10 = 2*5, we need to figure the highest powers of 2 and 5 dividing 100! and take the lesser of the two exponents. (Why?) Consider what happens when we multiply together 1*2*3*4*5*6*..., starting with the lowest numbers first. Every fifth number, starting with 5, is divisible by 5. That gives you 100/5 = 20 factors of 5 in 100!. But there are more. Every 25th number, starting with 25, has an extra factor of 5 beyond the ones already counted. That gives you 100/25 = 4 more factors of 5 in 100!. To get a third factor of 5 from a single number, it has to be a multiple of 125, and no number <= 100 is, so that is all. The answer is: [100/5] + [100/5^2] + [100/5^3] + ... = 20 + 4 + 0 + ... = 24 Here [x] means the integer part of x, or the greatest integer not exceeding x. (Why do we use this [x] instead of x?) All the terms from some point on will be zero, so this is a finite sum. Now for 2's (or any other prime number), the same analysis holds. The answer for the highest power of 2 dividing 100! is [100/2] + [100/2^2] + [100/2^3] + [100/2^4] + ... = 50 + 25 + 12 + 6 + 3 + 1 + 0 + 0 + ... = 97 The smaller of the two is 24, so the highest power of 10 dividing 100! is 10^24, so 100! ends with 24 zeroes.The same analysis works for any factorial n! and any prime p. The highest power of p dividing n! is: [n/p] + [n/p^2] + [n/p^3] + [n/p^4] + ... | |