I want to find out the number of $0$s in the number $30!$, what should I do? Is there any trick that would work for a general question of this type, like number of $0$s in $50!$ ?

- 53,687

- 2,002
-
4Trailing $0$'s (at the end), or can they be anywhere in the number? – pjs36 Jul 30 '15 at 01:27
-
1Yes all the 0s in the digit representation is required to count – Rescy_ Jul 30 '15 at 01:39
-
To the mods - this isn't a duplicate of the question. The question asks for the total number of zeros, while the other question asks for trailing zeros. – Jul 30 '15 at 01:47
-
@user122283 No, but it is a duplicate of this one: http://math.stackexchange.com/questions/266986/what-is-the-total-number-of-zeroes-in-n – Jul 30 '15 at 02:40
-
There's a similar job-interview question, but on $100!$ instead (you just need to calculate the number of times that the factor $2$ appears in all integers up to $100$, the number of times that the factor $5$ appears in all integers up to $100$, and take the minimum of those two values). – barak manos Jul 30 '15 at 08:03
4 Answers
For trailing zeroes its easy. A number will end in 0 if it is a multiple of 2 and 5.
The multiples of 5 between 0 and 30 are: $5, 10, 15, 20, 25, 30$ so you should expect there to be $7$ zeroes at the end of $30!$. (Notice $25 = 5^2$)
For the interior zeroes there's not short cut. You have to multiply out to discover both of them.
Also, $30! = 265252859812191058636308480000000$

- 129,094
-
The question does not specify whether or not the 0s should be in the end of the number or if it could also be somewhere in the middle of the number. – Jul 30 '15 at 01:33
-
You can use a program to see that $30!=265252859812191058636308480000000$. There are seven zeros in the end, and two in the middle. By sheer computation, this is nine zeros in $30!$. $50!=30414093201713378043612608166064768844377641568960512000000000000$, and we can count nineteen zeros in $50!$.
We can find a general formula as follows. First count the number of trailing zeros in $n!$. Since there are more factors of $2$ than factors of $5$ in $n!$, this means that there are: $$ \sum^\infty_{i=1}\left\lfloor{n\over5^i}\right\rfloor $$ zeros in the end of the number. Now, there are $\mathrm{log}(n!)$ digits in $n!$. In remaining digits (those which are not trailing zeros), each digit has $1/10$th of a chance of being a $0$, so we see that the number of zeros in $n!$ is approximated by: $$ \sum^\infty_{i=1}\left\lfloor{n\over5^i}\right\rfloor-\frac{1}{10}\left(\mathrm{log}(n!)-\sum^\infty_{i=1}\left\lfloor{n\over5^i}\right\rfloor\right) $$ Using Stirling's approximation, this gives about: $$\frac{9}{10}\sum_{i=1}^{\infty}\left\lfloor{\frac{n}{5^{i}}}\right\rfloor+\frac{1}{10}n\log_{10}n-\frac{n}{10\ln 10}+O(\ln n)$$ zeros in $n!$.
I don't think there's an closed form for this, but this gives a good approximation.
Hint: count the number of factors 2 and 5 which occurs in the numbers from 1 to 30.

- 402
-
1Well, not exactly. This would give you the number of 0's in the end. How about 0's inside the number itself? – Jul 30 '15 at 01:32
-
1you only need to count the number of $5$s, as there are more than enough $2$s; regardless, this only counts trailing zeros, and misses those in the interior. – obataku Jul 30 '15 at 01:32
-
1
-
I think the question refers to trailing zeros. Of course there are more 2s than 5s, but my hint was supposed to suggest also why you should count the factors – sintetico Jul 30 '15 at 01:36
The number $n!$ has $$\sum_{k\ge 1} \left\lfloor{n\over5^k}\right\rfloor$$ zeros at the end of the expanson

- 49,383
-
As mentioned in the comments of the other answer, the question doesn't explicitly refer to zeros at the end. – Akiva Weinberger Jul 30 '15 at 01:38
-
What occurs before the trailing zeroes appears to be entirely unpredictable. – ncmathsadist Jul 30 '15 at 01:38
-
-
-
-
-
-
If you have $n!$, the product $1\cdot 2 \cdot 3 .... n$ will have more factors of 5 than factors of 2. So every factor of 5 contributes a zero to the end of $n!$. Do you see it now? – ncmathsadist Jul 30 '15 at 01:42
-
-