Digit sum/product/properties of n!

412 Views Asked by At

How would one go about finding the digit sum/product/other properties of $n!$ and if not for $n!$, at least for $n$ too large for a calculator or computer to compute? ($n>1000$, let's say).

EDIT: People who answered with ways to program it are wrong. I asked for a mathematical way of doing it, i.e. without a computer.

3

There are 3 best solutions below

0
On

If you are looking at writing out 1000! or similar numbers, you are probably going to overflow the standard integer capability of ordinary computers. They usually allow for 32 bit integers, which I think is around 4 billion, and I think you would get past that very easily. So you first have a technical job, which is to build a way to store higher integers. I wouldn't be surprised if there is a program lying around somewhere which you could use; or if some languages like C have a built in method.

Most modern computers are close to nanosecond machines, so I don't see why 1000 multiplications should slow it down per se; your conversion to holding the digits might, depending on how many operations that requires.

Regarding possible algorithms which speed up the process, I don't know of any, but there may well be some; for sums it might be possible to take advantage of some symmetries. I know of nothing for products, other than approximations.

0
On

If you plan to write a computer program which returns the value of $n!$, you will face serious problems if you want the result as an integer since, for eaxmple, in C++ the largest integer value should be $2147483647$ which is lower than $13!$.

If you want for a result as a real number, you would be able to go further but not so much since $170!$ is already $7.25742\cdot10^{306}$.

Very often, it is not a single value of n! which is required but the result of operations such as ($m! n! / p!$) in which each term can be very large but the result of the operation "rather" small. Then, a way to do it is, when applicable, to compute $\log n!$, performs the operations using the logarithms and exponentiate the result. For sure, it will not be exact.

For large value of n, a very good approximation is given by Stirling (more or less extended formulas). Have a look at
http://en.wikipedia.org/wiki/Stirling%27s_approximation

1
On

$1000!$ has $2645$ decimal digits, using Stirling's approximation. Mathematica can calculate it easily, as can other packages.