Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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...

share|improve this question
    
Have you already checked your formula/algorithm against those provided by most mathematical programming packages? (Matlab, Mathematica, R, etc...) –  Raskolnikov Apr 22 '11 at 12:44
    
    
...or this one, which is similar: numbertheory.org/php/binomial.html –  Hans Lundmark Apr 22 '11 at 17:51

1 Answer 1

up vote 2 down vote accepted

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 ;
share|improve this answer
    
yes, except the characters aren't in that exact order. –  jokoon Apr 22 '11 at 18:50
    
WELL THEY SHOULD BE! –  TonyK Apr 26 '11 at 15:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.