## number of zeroes in 100 factorial.

I was on math.stackexchange the other day and i found a question that said How many zeroes are there in 100!. I quickly factored it out and said that there where 24 zeroes. However thats only the trailing zeroes (as the person who asked the question quickly pointed out). As the days passed no one answered the question. My question is the following: is there a method to figure it out without having to compute the whole answer? I initially thought that it could be solved using many divisibility properties but I didn't figure anything out.

-
For 100!, one can, as you say, simply compute it. But if we define $Z(n)$ to be the number of non-trivial zeros in the decimal expansion of $n!$, i.e., ignoring the ones coming from the factors of 5 in $n!$, then I don't see any easy way to compute, or even accurately estimate, $Z(n)$. Is it interesting to ask how, aside from the trivial trailing zeros, the digits of $n!$ are distributed? It's not so hard, I think, to show that the leading digits are Benford distributed, i.e., log uniform. – Joe Silverman Jul 13 at 2:57
Hello Joe Silverman. By that do you mean that there is no way of determining the zeroes in 100! without computing the whole number? – Omnitic Jul 13 at 3:02
Here is a link to a proof that the leading digits of $n!$ satisfy Benford's law : williams.edu/go/math/sjmiller/public_html/… I think Benford also conjectured that the frequency of a given digit in $n!$ tends to $1/10$ when $n \to \infty$, but this is probably out of reach... – François Brunault Jul 13 at 7:55
This is sequence oeis.org/A027869 , which has no interesting citations. – Kevin O'Bryant Jul 20 at 19:10
For the "tricks" that GMP uses in computing factorial, see page 105 of gmplib.org/gmp-man-5.0.5.pdf – Robert Israel Jul 20 at 20:10

It is unlikely. There are ways to compute the nth digit of certain numbers in certain bases (for example, pi in base 16) without having to compute the entire number, but in most situations, the number or formula for it either has very special properties (e.g. 101*10^n) in order to answer the question, or the work done to answer the question is tantamount to calculating the number, writing it down, and counting the digits. Not only do I know of no way to answer the question otherwise, I will wager a small amount of money that no such nice way will posted here for the next 2 years.

Gerhard "Willing To Formalize The Bet" Paseman, 2012.07.12

-
Well, that's not completely true. You would save a couple of minutes simply by eliminating 2^24*5^24 from the multiplication. – Omnitic Jul 13 at 3:08
The time saved is dependent and the speed of t and capacity of the multiplier. I agree that it has potential for simplifying the computation. One could also multiply prime powers together. It still smells to me like computing most if not all of the factorial first. Gerhard "Will Lower Yhe Wager Though" Paseman, 2012.07.13 – Gerhard Paseman Jul 13 at 17:25
I think you can say some things about the distribution of digits of some large products of small factors. Keep track of the distribution of subsequences of digits of a length larger than the largest factor. This distribution for $n$ almost determines the distribution for $n*a_i$ for $a_i$ small. However, you lose some control as you have more terms, and for $n!$ it looks like keeping track of the distribution of subsequences is as hard as multiplying the whole number out. – Douglas Zare Jul 13 at 18:18

Using well known approximations for the length and number of trailing zeroes of n!, and making the reasonable assumption that the inside zeros appear with frequency $\frac{1}{10}$, we get the following approximation of the total number of zeros, t, in n!:

$t = \lfloor \frac{1}{10}(\frac{\log (2 \Pi n)}{2}+n\log (\frac{n}{e})- \frac{n}{4}+ \log(n)) + \frac{n}{4} - log(n)\rfloor$

Which simplifies to:

$t = \lfloor \frac{n (9 \ln (10)-4)+4 (n-9) \ln (n)+2 \ln(2 \Pi n)}{40 \ln(10)} \rfloor$

This approximation seems to work well for n up to at least 10,000.

100!, with digit length 158, has less inside zeroes, 6, with 24 trailing, than the normal expectation for a total of 30, with t=36.

98! is "zero-perfect", i.e. inside zeroes appear with exactly frequency $1/10$, with actual total zero count 35 and $t = 35$

Other examples of zero-perfect factorials are: 1009!, 1097!, 1112!, 2993!, 6128!, ....

There appears to be a strong correlation of n having only 0-3 prime factors in {2, 3, 5} if n! is zero-perfect. Uneven n is often a prime number if n! is zero-perfect.

-
 Note that certain numbers have predictableffects. 100! has 2 'more zeros than 99!, which in turn is likely to "kill off" many zeros present in 98!. Can you give a theorem which says how the number of zeros in x and in 99 times x are related? Gerhard "Ask Me About System Design" Paseman, 2012.07.20 – Gerhard Paseman Jul 21 at 3:47

EDIT: this doesn't really work. I'm still a good human being.

Evenly enough, it seems possible to get the number of zeros in the binary expansion of $n!$

One can get a fairly accurate expression for $$\log_2 \; n! = \frac{\log \; n!}{\log 2}$$ from using extra terms in Stirling's formula. Taking the floor of that and adding 1 gives the total number of digits in base two..

Legendre's formula $$v_2(n!) = \left\lfloor \frac{n}{2} \right\rfloor + \left\lfloor \frac{n}{4} \right\rfloor + \cdots$$ has a companion,

$$v_p(n!) = \frac{n - S_p(n)}{p-1}$$ where $S_p(n)$ is the sum of the digits when $n$ is written in base $p.$ As all the digits in a base two expansion are $1,$ we find that $S_2(n)$ is simply the count of 1's in the base two expansion of $n.$

Alright, some people, who shall remain nameless, have attempted to cast aspersions on the reputation of your humble servant, pointing out that the number of ones in the binary expansion of $n!$ is not the same as the number of ones in the binary expansion of $n$ itself. I try so hard. Don't change the light bulb, I'll just sit here in the dark.

-
That would be nice if it were the count of $1$'s in the base two expansion of $n!$. – Robert Israel Jul 13 at 3:51
Well, crap. ${}{}{}{}{}$ – Will Jagy Jul 13 at 3:57
Maybe we can do something with $v_p(n!!)$ – SJR Jul 13 at 7:21

Given a prime $p$, it occurs $m$ times in the prime factorization of $n!$, where

m = $\lfloor \frac{n}{p} \rfloor + \lfloor \frac{n}{p^2} \rfloor + \lfloor \frac{n}{p^3} \rfloor + \cdots$

This is explained in many number theory books. Apply this for $p=2$ and $p=5$, and use the value you get for 5, since this occurs many fewer times.

Tom

-
 Well, this is just the simple answer for the trailing zeroes. I know no way to get ALL the zeroes. – Tom Dickens Jul 13 at 2:57 Thanks but that was not what i was asking for. Your solution only applies to the trailing zeroes while i wanted to know all of the zeroes. – Omnitic Jul 13 at 2:58