Counting the zeros in a factorial expansion [closed]

A number, as big as 1000! (! = factorial) is given. I need to find how many zeros are there in the number. I counted the no of terminal zeros by dividing 5, 25, 125, ... (untill fifth power < number). But thats just a part of it. I also need to count number of zeros in between the digits. For example 8! has a zero after 4 (40320). I need to count those to.

I spent hours still got nothing :P

Is it actually even possible? I am trying to write a program in C++ to count. I could divide the number by 100 and count zeros but 1000! is too huge even for a 64bit computer.

Any ideas, algorithms, formulae?

-

closed as off-topic by Artes, Jens, Michael E2, m_goldberg, Yves KlettAug 26 '14 at 11:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Jens, m_goldberg, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

This question appears to be off-topic because it is about programming in C++ –  Simon Woods Aug 25 '14 at 16:46
Sorry for not being clear.I was trying to get the algorithm in mathematica then try to implement it in C++.I do it everytime.But this time its hard to port it to C++ lol :D –  Yashas Samaga Aug 25 '14 at 16:48
nope, not the same, I already know to count zeros which are at the right end.But here I want the count the zeros in between too. –  Yashas Samaga Aug 25 '14 at 16:51
You only need to apply DigitCount to the factorial. –  Jens Aug 25 '14 at 18:51

Count[IntegerDigits[#!], 0] & /@ Range[1, 100000, 2000] // ListLogPlot


-
Let us note for the record that Count[IntegerDigits[1000!], 0] gives the result 472, essentially instantaneously. –  m_goldberg Aug 25 '14 at 17:05

Counting Strings may be faster, so I propose the string version:

countZeros[x_Integer] := StringCount[IntegerString[x!], "0"]


Then:

countZeros[1000]


472

-
Indeed, First@Timing@Count[IntegerDigits[1000!], 0] gives 0.000198 whereas First@Timing@countZeros[1000] gives 0.000157. Moreover, on my system, First@Timing@Count[IntegerDigits[10000!], 0] give 0.003858 whereas First@Timing@countZeros[10000] gives 0.002740. –  murray Aug 25 '14 at 19:06
@murray. Thanks for confirming my suspicion. –  RunnyKine Aug 25 '14 at 19:40