Say I have some natural number $m$. I want to find the natural number $n$ with the property that $n!$ is the largest factorial less than $m$. For instance, if $m = 17$, then $n = 3$ since $3! = 6$ but $4! = 24$. Is there an elegant way to do that?
Asked
Active
Viewed 149 times
0
-
Related: https://math.stackexchange.com/questions/2078997/inverse-of-a-factorial – Matti P. Oct 28 '20 at 13:43
-
Use Stirling's formula for $n!$ and then invert this using the Lambert $W$ function ? – Donald Splutterwit Oct 28 '20 at 13:46
-
If $m$ is not too big, this can be found out with brute force. For huge $m$ , you can use the gamma function or Stirling's approximation. If $m$ is extremely close to a factorial, this might give a wrong answer however. A very efficient function doing the job in PARI/GP is : fac(m)={s=1;n=1;while(n<=m,s=s+1;n=n*s);s-1} needing only seconds even for numbers around $10^{10^6}$ – Peter Oct 28 '20 at 13:49
-
@DonaldSplutterwit that seems like a valid answer, if you write it up I'll accept it – Michael Stachowsky Oct 28 '20 at 14:36
1 Answers
1
$n!=\Gamma(n+1)$
As $n\to +\infty$ we have $$\Gamma(n+1)\sim e^{-n} n^n \left(\sqrt{2 \pi n}+\frac{1}{6} \sqrt{\frac{\pi }{2 n}}\right)$$
Thus if we want $n$ such that $n!<10^6$ we solve numerically $$ e^{-n} n^n \left(\sqrt{2 \pi n}+\frac{1}{6} \sqrt{\frac{\pi }{2 n}}\right)=10^{20}$$ $n\approx 21.2185$. Take $\lfloor n \rfloor=21$
Indeed $21!\approx 5.1\times 10^{19}<10^{20}$

Raffaele
- 26,371