1

I'm writing computer program which on some point has to compute following formula: $${n\choose k} - {n\choose k-1}$$ Because I have following limits: $$n \le 4000, \space k \le\frac{n}{2}$$ computing it straightforward using factorial would involve very big numbers. So I was wondering if it can be reduce somehow?

Ian Mateus
  • 7,431
Kostek
  • 255

2 Answers2

2

If you compute $\binom{n}{k}$ by repeated use of the identity $\binom{n}{k}=\frac{n-k+1}{k} \binom{n}{k-1}$, you'll never have to deal with numbers that are much larger than your final result. You also get $\binom{n}{k-1}$ for free...

Micah
  • 38,108
  • 15
  • 85
  • 133
0

By definition

$$\binom nk-\binom n{k-1}=\frac{n!}{k!(n-k)!}-\frac{n!}{(k-1)!(n-k+1)!}=$$

$$=\frac{n!}{(k-1)!(n-k)!}\left(\frac1k-\frac1{n-k+1}\right)$$

It doesn't look very nice...if instead that "$\;-\;$" there was a "$\;+\;$" it'd be rather nice.

DonAntonio
  • 211,718
  • 17
  • 136
  • 287