28
$\begingroup$

I don't want to do this through trial and error, and the best way I have found so far was to start dividing from 1.

$n! = \text {a really big number}$

Ex. $n! = 9999999$

Is there a way to approximate n or solve for n through a formula of some sort?

Update (Here is my attempt):

Stirling's Approximation: $n! \approx \sqrt{2 \pi n} \left( \dfrac{n}{e} \right ) ^ n$

So taking the log:

$(2\cdot \pi\cdot n)^{1/2} \cdot n^n \cdot e^{-n}$
$(2\cdot \pi)^{1/2} \cdot n^{1/2} \cdot n^n \cdot e^{-n}$
$.5\log (2\pi) + .5\log n + n\log n \cdot -n \log e$
$.5\log (2\pi) + \log n(.5+n) - n$

Now to solve for n:

$.5\log (2\pi) + \log n(.5+n) - n = r$
$\log n(.5+n) - n = r - .5 \log (2\pi)$

Now I am a little caught up here.

  • 0
    [Related...](http://math.stackexchange.com/questions/18362)2011-09-04

2 Answers 2

20

A good approximation for $n!$ is that of Stirling: $n!$ is approximately $n^ne^{-n}\sqrt{2\pi n}$. So if $n!=r$, where $r$ stands for "really large number," then, taking logs, you get $\left(n+\frac12\right)\log n-n+\frac12\log(2\pi)$ is approximately $\log r$. Now you can use Newton's method to solve $\left(n+\frac12\right)\log n-n+\frac12\log(2\pi)=\log r$ for $n$.

  • 4
    Thanks for fixing the sign. I made another mistake, writing $r$ where I needed $\log r$ at the end. I'll fix that one. Doug, all the log is doing is making the problem look a little nicer. You *can't* isolate $n$; what you can do, as I said, is use Newton's Method, which you can look up. Newton's Method uses Calculus. If you haven't done Calculus yet, you could start by seeing how close $n=\log r/\log\log r$ is to a solution, and then go a little higher or lower as necessary.2011-09-04
6

$\exp(1+W(\log(n!)/e))-\frac{1}{2}\searrow n$ as $n\to\infty$where $W$ is the Lambert W function. For integer $n\ge2$, the floor is exact.

I just took the expansion out a bit more and the approximation I gave above overestimates $n$ by $\log\left(\sqrt{2\pi}\right)/\log(n)$.

  • 0
    The approximation $ n\sim e\exp\left(\operatorname{W}\left(\frac1{e}\log\left(\frac{n!}{\sqrt{2\pi}}\right)\right)\right)-\frac12 $ from [this answer](https://math.stackexchange.com/a/2079043) is closer2017-11-10