# Thread: factorial for big numbers

1. ## factorial for big numbers

I need a way to find factorail for big numbers like 8479!

raju

2. Originally Posted by raju
I need a way to find factorail for big numbers like 8479!

raju
A simple way.
Just multiply them out.

3. Originally Posted by raju
I need a way to find factorail for big numbers like 8479!

raju
See Stirlings formula (equations 13 and 14 here)

RonL

4. Originally Posted by CaptainBlank
See Stirlings formula (equations 13 and 14 here)

RonL
That is only an approximation.

5. Originally Posted by ThePerfectHacker
That is only an approximation.
How many digits does 8479! have?

(Rhetorical question)

RonL

6. Originally Posted by CaptainBlack
How many digits does 8479! have?

(Rhetorical question)

RonL
Over 29,000.

25972686487041052159869258722936182200373790277711 48344797668281885988268302193747006721558615751528[...29429 digits...]00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000

7. Originally Posted by CaptainBlack
How many digits does 8479! have?

(Rhetorical question)

RonL
I can find how many zeros is has .

8. i had this problems some weeks back. Stirlings function is probably the best for large factorials. But otherwise use this bit of code i wrote in java which is computationally efficient.

public double gammaln(float xx){
double x,y,tmp,ser;
double[] cof={76.18009172947146,-86.50532032941677,
24.01409824083091,-1.231739572450155,
0.1208650973866179e-2,-0.5395239384953e-5};
int j;
y=x=xx;
tmp=x+5.5;
tmp -= (x+0.5)*Math.log(tmp);
ser=1.000000000190015;
for (j=0;j <= 5;j++) {ser += cof[j]/++y;}
return -tmp+ Math.log(2.5066282746310005*ser/x);}

public double factorial(float n){
double value = gammaln(n + 1);

This is based around a method of gamma approximation by C.lanczos. (Paper is called - (A precision approximation of the gamma function).

This method can also be used to find NON integer factorials

9. I think ur asking this for a question like "find the lowest common multiple" (LCM)

there is no need to use massive formulas unless the number is greater then 1trillion.

just use Prime factorisation.

eg. 4 = 2 power of 2
6 = 3 x 2
1001 = 7 x 11 x 13
etc...

take the number and find all possible prime numbers which go ito it. (see examples above)
then...

eg. find the lowest common multiple of 4, 2, 6
4 = 2 squared 2 = 2 and 6 = 2x3
therfore the number must contain 2 squared and 3.
= 2 squared x 3
= 12

find all prime factors of the numbers. and take the common ones out
eg. 2 squared and 2
only use 2 squared because 2 is within 2 squared

then multiply them together.

(i can go on but it would just be useless)

10. Originally Posted by spanner
I think ur asking this for a question like "find the lowest common multiple" (LCM)
How does this relate to finding the factorial of a large number?

RonL

11. Originally Posted by CaptainBlack
How does this relate to finding the factorial of a large number?

RonL
it gives the base of a number in its prime factors,

then u can use all of theose prime numbers in different combinations to find the factors

12. Originally Posted by spanner
it gives the base of a number in its prime factors,

then u can use all of theose prime numbers in different combinations to find the factors
This is incomprehensible, please give us an example

RonL

13. hang on maybe some confusion. spanner were finding a method of carrying out the factorial function not the LCM. I dont see how in anyway ur method can find the factorials of large numbers.

14. Originally Posted by chogo
hang on maybe some confusion. spanner were finding a method of carrying out the factorial function not the LCM. I dont see how in anyway ur method can find the factorials of large numbers.
I think that is what I was trying to indicate, indirectly so as not to cause offence .

RonL