Find the smallest $n$ for which $n!$ has more than $k$ digits for a given integer $k>0$

102 Views Asked by At

Given any positive integer $k$, how can I find the smallest $n$ for which $n!$ has more than $k$ digits?

I have boiled the question down to:

$$\mathrm{floor}(\log(n!)) + 1 = k$$

But cannot simplify this any further.

Please help me. I'm going crazy over this problem.

1

There are 1 best solutions below

0
On

As @Angelo commented, you want to solve for $n$ (for a given $k$) the equation $$n! \geq 10^k$$

I f you look here, there is a superb approximation from @Gary. Here is the exact solution given by @robjohn

$$\color{blue}{\large n=\left\lceil e^{1+W\left(\frac 1e {\log \left(\frac{10^k}{\sqrt{2 \pi }}\right)}\right)}-\frac{1}{2}\right\rceil}$$ where $W(.)$ is Lambert function.

For $k=123456789$ this gives $n=18093598$ and $18093598!$ has $123456793$ digits