Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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|cite|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: – Hans Lundmark Apr 22 '11 at 17:51
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|cite|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


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.