Solve the equation for $x$: $$x!=n$$ where $x,n \in \mathbb N$.
(Here $n \in \mathbb N$ is a given number such that $x!=n$ has a solution in $x \in \mathbb N$.)
The problem is easy with a calculator and for small $n$. But I want to solve this for large $n$ without a calculator (Why? Just curious!).
Here is an example of how large $n$ can be: $$x!=523 022 617 466 601 111 760 007 224 100 074 291 200 000 000$$ (Here $n$ is a $45$-digit number and $x=38$.)
To solve the equation, I could think of two methods. Here is their description:
Method 1 - prime factorization:
In this method, we find the prime factorization of $n$. To do this, we keep dividing $n$ by $2$ until we get an odd number. This is equivalent to finding $\log_2 n$. But since $n$ is a large number, it is very difficult and long process.
For the example problem, we have to divide $n$ by $2$, $35$ times. Yet this doesn't give the exact answer. Since $\lfloor 38/2 \rfloor + \lfloor 38/2^2 \rfloor + \dots =\lfloor 39/2 \rfloor + \lfloor 39/2^2 \rfloor + \dots=35$ this implies that $x=38$ or $x=39$. We have to divide the $n$ by $13^3$ to be sure that $x=38$ is the solution.
Method 2 - Stirling's approximation:
In this method, we use the Stirling's approximation formula, which is $x! \sim \sqrt {2\pi x}(\frac x e)^x$. But it is not easy to find $x$ in terms of $n$. Here is my workings to do that: $$x!=n$$ $$\implies \sqrt {2\pi x}(\frac x e)^x=n$$ $$\implies 2\pi x (\frac x e)^{2x}=n^2$$ $$\implies x^ {2x+1}\cdot \frac 1 {e^{2x}}=\frac {n^2}{2\pi}$$
I am unable to proceed after that. But I don't think the derived equation can solve for $x$ in terms of $n$ without using a calculator (or at least this would be too hard).
I hope my workings are correct. So, is there some easier way to solve the equation? And how do I complete my workings on method 2?
Solve[x! == 523022617466601111760007224100074291200000000, x, Integers] // AbsoluteTimingresults in{0.0141206, {{x -> 38}}}. – user64494 Jul 02 '21 at 14:09