0
$\begingroup$

With the $C_n^k$ formula, I managed to optimize it for finding very big numbers such as $C_{7130}^{7125}$ rather quickly. I could have used GMP or Ruby because unsigned long don't hold a lot of values, but here is my question:

Are there applications where people need to compute such numbers ? Because the plain factorial methods can be quite long compared to my method...

  • 0
    Have you already checked your formula/algorithm against those provided by most mathematical programming packages? (Matlab, Mathematica, R, etc...)2011-04-22
  • 0
    Or this one: http://www.luschny.de/math/factorial/FastBinomialFunction.html (based on http://www.jstor.org/pss/2323099)?2011-04-22
  • 0
    ...or this one, which is similar: http://www.numbertheory.org/php/binomial.html2011-04-22

1 Answers 1

2

Yes, there are all sorts of reasons why you might want to know a large binomial coefficient. Is this what you have?

some_int_type nCr = 1 ;
if (r > n/2) r = n - r ;
for (int i = 1 ; i <= r ; i++, n--)
  nCr *= n, nCr /= i ;
  • 0
    yes, except the characters aren't in that exact order.2011-04-22
  • 0
    WELL THEY SHOULD BE!2011-04-26