# First decimal digits of factorial $n$ divided by $x$

Actually, I will reformulate the question: how can I find a formula to calculate the nth decimal digit (the non-integer part) of f(x,n) = n!/x ? My idea is a Taylor serie of some kind but I don't know where to start. Any idea?

Formulated this way, the size of n and x is not relevant since I am looking for a formula.

This was the original question:

Consider we got a really big integer number, $n!$ where $n$ is at least $10$ digits long. I would like to calculate the $10$ first decimal digits of $\frac {n!}{x}$. Is there a practical way of doing this?

-
I don't think the "divided by $x$" part is relevant. If you know $n!$ within one part in $10^{10}$, say, then you know $n! / x$ with the same tolerance, whatever $x$ is. – mjqxxxx Nov 21 '12 at 21:10
And the way to know the most significant digits of $n!$ is Stirling's approximation. – Gerry Myerson Nov 22 '12 at 0:15
In my case it is relevant because I am interested by the decimal part only and it is important that I can get at least a couple of exact digits. Does the Stirling formula sufficiently accurate to get at least a couple of decimal numbers exactly ? – Nicolas Dec 5 '12 at 13:21

First, you want to find $n! \pmod x$. Then you can just use long division to get all the places you want. Depending on your computer, direct computation works fine up to $n \approx 10^8$ or so. You never need to handle a number bigger than $nx$.

-
I would have hoped for something more efficient but I'll accept that answer since it does what I asked for. Thanks! – Nicolas May 13 '13 at 19:38

Considering only $n!$, this makes a huge difference. What are the "first digits"? Are they from the left (the way we read a number in English) or from the right (the way usually done in Math)? If they are from the right like the units, ten, hundreds digits then the answer is easy for a large n factorial. As long as n is bigger than $44$, the first ten digits on the right will be all zeros. If you want the first ten nonzero digits from the right, Its highly nontrivial but I know for a fact it can be done but I don't remember the details of the method right now. You need some tricks with number theory and a bit of programming.

Since you say the decimal part of $\frac{n!}{x}$ you probably want the digits to right of the decimal point in $\frac {n!}{x}$. It would also depend on the size of $x$. How small or big is it? And at first thought its also looks like it would depend if $x$ is rational or irrational. If you do $\frac{100!}{2}$, the decimal part is zero because $2$ is a factor of the numerator. If you do $\frac {100!}{\frac13}$ well then the decimal part is zero again. And if you try $\frac {100!}{\frac23}$ then this is also a whole number with the decimal part being zero.

-
Yes, I mean the digits to the right of the decimal point. For my case, x is greater than n² and it is an integer. – Nicolas Dec 5 '12 at 13:33
Could you give me a typical x and n? From top of my head, it looks to me the tips/tricks would depend a lot on what $n$ and $x$ actually are. – Fixed Point Dec 6 '12 at 3:58
$n$ and $x$ are abstract integer. I reformulated the question to be more clear. – Nicolas Dec 6 '12 at 20:28