I need a way to find factorail for big numbers like 8479!
Thanks in advance
raju
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);
double answer = Math.exp(value);
return answer;}
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
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)