0

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.

TShiong
  • 1,257
Mani
  • 402
  • This is a well known exercise, see for example this post for $k=10$. In general you may need Sterling's formula. You can find this question at several sites, e.g., at geeksforgeeks, etc. Start searching! – Dietrich Burde Jan 16 '23 at 19:54
  • 1
    @Shagester, you should have written that $;\mathrm{floor}\big(!\log(n!)\big)+1>k;$ instead of $;\mathrm{floor}\big(!\log(n!)\big)+1=k,.;$ Moreover , $;\mathrm{floor}\big(!\log(n!)\big)+1>k;$ is equivalent to $;n!\geqslant10^k;.$ – Angelo Jan 16 '23 at 20:29
  • @angelo wouldn't the fact taht we are taking the floor of the log of n! before we add one assure that it will be the lowest integer such that it has k integers? – Mani Jan 17 '23 at 04:41
  • @Shagester, you have to find the smallest $n$ such that $n!$ has *more* than $k$ digits, so you have to write $”\color{blue}{\mathbf{>k}}”$ instead of $”\color{red}{\mathbf{=k}}”$. Have you understood now? – Angelo Jan 17 '23 at 05:15

1 Answers1

1

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