My software application receives a series of very large integers (hundreds of decimal digits). So far, I have been using string/textual representation of decimal digits for very simple manipulation (calculating on the number of digits, etc.).
I want to find the highest $n$ in $n=ReverseFactorial(x)$ where $x$ is the big integer I already have. Examples of expected results would be:
- $4=ReverseFactorial(24)$
- $4=ReverseFactorial(25)$
- $4=ReverseFactorial(119)$
- $5=ReverseFactorial(120)$
- $5=ReverseFactorial(719)$
- $6=ReverseFactorial(720)$
I can convert $x$ into its respective decimal or binary notation if either of those number systems could help in calculating $n$ very fast. As an example, finding the base 2 log for a very large number is possible by inspecting the most significant bit. Is there such a solution for factorials? Could the number of digits provide a clue?
UPDATE: Based on ShreevatsaR's answer, it appears that if the number to be tested is not an exact factorial (which it is not in my case), there is no efficient way to determine $n$. I wanted to verify this here so I can move on to other ways of addressing my context.
You can use Stirling's approximation $n! \approx \left(\frac ne \right)^n\sqrt {2\pi n}, \log n! \approx n(\log n -1)+1.838 +\frac 12 \log n$ and iteration: start with $n_0=\log x,$ then $n_1=\frac {\log x}{\log n_0}$ will bracket the root. Use you favorite root finder, which should converge quickly.