How many 0's are at the end of 20!

I'm not exactly sure how to answer this question, any help would be appreciated. After reading this I'm still not sure.

Cheers

-
Does this site answer it and walk through enough details? purplemath.com/modules/factzero.htm, using the number of fives method or Wolfram Alpha: wolframalpha.com/input/?i=number+of+trailing+zeros+in+20%21 –  Amzoti Oct 18 '12 at 1:09
That's funny, I literally just stumbled across this site. –  Unknown Oct 18 '12 at 1:10
Evidently there is only one! (sorry, couldn't resist) –  treble Oct 18 '12 at 1:34
I got asked this in a programming job interview once, but for $100!$ - I didn't get the job :( –  Ergwun Oct 18 '12 at 6:50

There is a general formula that can be used. But it is good to get one's hands dirty and compute.

If $20!$ seems dauntingly large, calculate $10!$. You will note it ends with two zeros. Multiplying $10!$ by all the numbers from $11$ to $20$ except $15$ and $20$ will not add to the zeros. Multiplying by $15$ and $20$ will add one zero each.

Remark: Suppose that we want to find the number of terminal zeros in something seriously large, like $2048!$. It is not hard to see that this number is $N$, where $5^N$ is the largest power of $5$ that divides $2048!$. This is because we need a $5$ and a $2$ for every terminal $0$, and the $5$s are the scarcer resource.

To find $N$, it is helpful to think in terms of money. Every number $n$ between $1$ and $2048$ has to pay a $1$ dollar tax for every $5$ "in it." So $45$ has to pay $1$ dollar, but $75$ has to pay $2$ dollars, because $75=5^2\cdot 3$. And a $5$-rich person like $1250$ has to pay $4$ dollars.

Let us gather the tax in stages. First, everybody divisible by $5$ pays a dollar. These are $5$, $10$, $15$ and so on up to $2045$, that is, $5\cdot 1, 5\cdot 2,\dots, 5\cdot 409$. So there are $409$ of them. It is useful to bring in the "floor" or "greatest integer $\le x$ " function, and call the number of dollars gathered in the first stage $\lfloor 2048/5\rfloor$.

But many numbers still owe some tax, namely $25,50,75,\dots,2025$. Get them to pay $1$ dollar each. These are the multiples of $25$, and there are $\lfloor 2048/25\rfloor$ of them.

But $125$, $250$, and so on still owe money. Get them to pay $1$ dollar each. We will gather $\lfloor 2048/125\rfloor$ dollars.

But $625$, $1250$, and $1875$ still owe money. Gather $1$ dollar from each, and we will get $\lfloor 2048/625\rfloor$ dollars.

Now everybody has paid up, and we have gathered a total of $$\lfloor 2048/5\rfloor + \lfloor 2048/25\rfloor +\lfloor 2048/125\rfloor +\lfloor 2048/625\rfloor$$ dollars. That's the number of terminal zeros in $2048!$.

-
I don't always upvote answers that are in "competition" with my own...but when I do, it's because it's a damn good answer! (+1) –  Cameron Buie Oct 18 '12 at 3:59
Yours is a good answer, now with an additional upvote. I thought that this might be an opportunity to describe in very concrete terms the process that yields the usual formula. –  André Nicolas Oct 18 '12 at 4:13
Agreed. You did it much more explicitly and intuitively than I (though, to be fair, I'd never even realized that there was an explicit formula before, and was operating off the cuff). Upvote appreciated. –  Cameron Buie Oct 18 '12 at 4:33

Count up the number of factors of $5$ and the number of factors of $2$ in $20!$. Since we get a zero for every pair of factors $5\cdot 2$, then the minimum of these will answer your question. More simply, $5$ happens less often as a factor (since it's bigger than $2$), so we need only count up the number of $5$'s. In particular, there's one each in $5,10,15,20$, so there are $4$ zeroes at the end.

If the problem had asked about $25!$, then there'd be $6$ zeroes--not $5$--because there are two factors of $5$ in $25$. Similar idea for other numbers.

-
It gets harder when you try it with bases other than 10. –  marty cohen Oct 18 '12 at 1:44
That's true, Marty, though not relevant to the context. –  Cameron Buie Oct 18 '12 at 1:52

General formula (for the interested) about the number of zeroes in n! in any base (b). First consider all prime factors of b, then consider the biggest one (p). Then use this formula.

$\lfloor n/p \rfloor$ + $\lfloor n/p^2 \rfloor$ + $\lfloor n/p^3 \rfloor$ + ....

This and using the fact that, the floor becomes zero after some exponent, you can calculate the number of zeroes in any base.

Thanks

Salahuddin

http://maths-on-line.blogspot.in/

-