How one can find the total number of digits in $n!$ raised to power $n$ where $n$ is in the millions?

60 Views Asked by At

I need to find the total number of digits in $(n!)^n$.

For example:

n=5 
n!=120 
(n!)^n=24883200000 

The total number of digits in the example is 11.

2

There are 2 best solutions below

0
On BEST ANSWER

The number of digits is Since $\left\lfloor\log_{10} n!^n+1\right\rfloor=\left\lfloor\tfrac{n\ln n!}{\ln 10}+1\right\rfloor$, since $n!^n$ cannot be a power of $10$ (as you can prove by counting how often $2,\,5$ divide $n!$). If you'll settle for an approximate answer, use $\ln n!\approx\ln\sqrt{2\pi n}+n(\ln n-1)$; if you need an exact answer, have a computer compute $\ln n!$ as $\sum_{k=1}^n\ln k$.

0
On

This simple Mathematica script generates results fairly quickly on my outdated MacBook, even for $n>10^6$

In[7]:= numDigits[n_] := Floor[n Sum[Log10[k], {k, 1, n}]] + 1

In[8]:= numDigits[5]

Out[8]= 11

In[9]:= numDigits[1000]

Out[9]= 2567605

In[10]:= numDigits[1000000]

Out[10]= 5565708917187

In[11]:= numDigits[10000000]

Out[11]= 656570590800575