C++ program to calculate quotients of large factorials -


how can write c++ program calculate large factorials.

example, if want calculate (100!) / (99!), know answer 100, if calculate factorials of numerator , denominator individually, both numbers gigantically large.

expanding on dirk's answer (which imo correct one):

 #include "math.h" #include "stdio.h" int main(){   printf("%lf\n", (100.0/99.0) * exp(lgamma(100)-lgamma(99)) ); } 

try it, want though looks little crazy if not familiar it. using bigint library going wildly inefficient. taking exps of logs of gammas super fast. runs instantly.

the reason need multiply 100/99 gamma equivalent n-1! not n!. yeah, exp(lgamma(101)-lgamma(100)) instead. also, gamma defined more integers.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -