Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to calculate with how many zeros 1000! ends. This is wat I did, but I am not sure whether its good: I think I have to calculate how many times the product 10 is in 1000!. I found out the factor 10 is 249 times in 1000! using the fact that $s_p(n!)=\sum_{r=1}^{\infty}\lfloor \frac{n}{p^r}\rfloor$. So I think the answer should be that it ends with 249 zeros.

Is this correct/are there other ways to do this? If not how should I do it then?

share|cite|improve this question
Hint: find out the number of 2's and 5's in $\,1,000!\,$..and yes, this is basically what you did, yet the formula you wrote works for primes, so better to separate 2's and 5's. – DonAntonio Feb 5 '13 at 18:49
@DonAntonio yes thats what I did because 10=2*5. there are 249 times 5 and more than 249 times 2. – Badshah Feb 5 '13 at 18:51
up vote 2 down vote accepted

First, let's note that $10$ can be factored into $2 \times 5$ so the key is to compute the minimum of the number of $5$'s and $2$'s that appear in $1000!$ as factors of the numbers involved. As an example, consider $5! = 120$, which has one $0$ because there is a single $5$ factor and a trio of $2$ factors in the product, one from $2$ and a pair from $4$.

Thus, the key is to compute the number of $5$'s, $25$'s, $125$'s, and $625$'s in that product as each is contributing a different number of $5$'s to the overall product as these are the powers of $5$ for you to consider as the $2$'s will be much higher and thus not worth computing.

So, while there are 200 times that $5$ will be a factor, there are 40 times for $25$ being a factor, eight for $125$ and one for $625$, which does give the same result as you had of 249, though this is a better explanation.

share|cite|improve this answer

actually you should think about factor 5 rather than 10.

share|cite|improve this answer
Because for each 5 in $n!$ you'll get (a bit more than) two 2s, and so counting 5s is enough. – vonbrand Feb 5 '13 at 18:52

Also, your sum doesn't have to go to infinity. As you no doubt noticed, the sum itself is finite and the terms after a first few finite terms are all zero. We actually know exactly where we can truncate the sum. We will stop when we hit the largest power of $p$ dividing $n$ which can easily be found by $\left\lfloor \frac{log(n)}{log(p)} \right\rfloor$ because after that the fraction will be less than one so taking its floor will always give zero. So your sum can be written as

$$\sum_{r=1}^{\left\lfloor\frac{\log(n)}{\log(p)}\right\rfloor} \left\lfloor\frac{n}{p^r}\right\rfloor$$

share|cite|improve this answer

Actually, what you want to count is the number of $5$'s. If you count how many multiples of $5$ show up (multiples of $25$ should be counted twice, and multiples of $125$ should count for three times), you will get the number of $5$'s in the prime factorization of $1000!$

Similarly, you can count the number of $2$'s in the prime factorization of $1000!$. This number will be much greater.

Since $10=2\times 5$, for each $5$ and $2$ in the prime factorization, you get a power of $10$, ie. a $0$ at the end of the number. So the number of $0$'s will be whichever is less, the number of $5$'s or the number of $2$'s.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.