I am trying to solve $n! = 10^6$ for $n$. I thought to do this using the gamma function:

$$(n - 1)! = \Gamma(n) = \int_0^\infty x^{n - 1}e^{-x} \ dx$$

So I have that

$$\Gamma(n + 1) = \int_0^\infty x^n e^{-x} \ dx = 10^6$$

I thought to solve this using integration by parts:

$$\begin{align} \Gamma(n + 1) &= \int_0^\infty x^n e^{-x} \ dx \\ &= [-x^n e^{-x}]^{\infty}_0 + \int_0^{\infty} nx^{n - 1}e^{-x} \ dx \end{align}$$

But, as you can see, unless I have made a mistake, we get the term $\int_0^{\infty} nx^{n - 1}e^{-x} \ dx$, which, as far as I can tell, means that we get stuck in an infinite loop of integration by parts.

So how do I solve this?

Thank you.

  • 1
    $\begingroup$ There is no such natural number $n$, because if $n!$ is divisible by $5$, then it must be divisible by $3$. If you solve $\Gamma(x + 1) = 10^6$, then a real solution should exist, but it won't be an integer. Is this what you want? $\endgroup$ – user754697 Mar 4 '20 at 4:52
  • 1
    $\begingroup$ Are you sure that is the equation you want? $10^6=2^65^6$ only has prime factors $2$ and $5$, but $n!$ is divisible by $3$ for all $n\geq 3$. $\endgroup$ – Dave Mar 4 '20 at 4:53
  • $\begingroup$ @user754697 To reply to you both, I am solving a computational (time) complexity problem from my textbook. It says that $n! = 10^6$, where we have $10^6$ microseconds in a second, means that $n = 9$. Does that clarify things? $\endgroup$ – Dom Fomello Mar 4 '20 at 4:55
  • $\begingroup$ This is WolframAlpha's calculation: wolframalpha.com/input/?i=n%21+%3D+10%5E6 $\endgroup$ – Dom Fomello Mar 4 '20 at 4:59

If you look at this question, you will find a very good approximation of the inverse of the factorial function.

Applied to your case $$n! =y$$it write

$$n \sim \frac{{\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)}}{{W\left( {\frac{1}{e}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right)}} -\frac{1}{2}$$ and, for $y=10^6$, it will give $n=9.44379$ while the exact solution is $9.44561$.


Using WolframAlpha, I get $n=9.4456089144163262435935599652$, but thats about as far as I can figure. There's not really a good way to reverse the Gamma function to solve something like that besides numerical approximations.

  • 1
    $\begingroup$ Look at the link. It is a wonderful approximation. $\endgroup$ – Claude Leibovici Mar 4 '20 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.