2013
11-11

# Binomial Showdown

In how many ways can you choose k elements out of n elements, not taking order into account?

Write a program to compute this number.

The input will contain one or more test cases.

Each test case consists of one line containing two integers n (n>=1) and k (0<=k<=n).

Input is terminated by two zeroes for n and k.

For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 231.

Warning: Don’t underestimate the problem. The result will fit into an integer – but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.

4 2
10 5
49 6
0 0


6
252
13983816


//* @author  [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.io.IOException;
import java.util.StringTokenizer;
public class Main {
static long[][] M=new long[2000][2000];
public static long comb(int n,int k){
if(k>(n/2))k=n-k;
if(n< 2000&&k< 2000) return M[n][k];
else if(k==n||k==0) return 1;
else if(k==1) return n;
else return comb(n-1,k)+comb(n-1,k-1);
}
public static void main(String[] args) throws IOException {
StringTokenizer token;
int n=0,k=0;
for(int i=0;i< 2000;i++){
M[i][i]=1;
M[i][0]=1;
M[i][1]=i;
M[0][i]=0;
}
for(int i=1;i< 2000;i++){
for(int j=2;j< 2000;j++){
if(i!=j){
M[i][j]=M[i-1][j-1]+M[i-1][j];
}
}
}
while(true){
}