// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigInteger;

public class NumComb {
    public static BigInteger fac(int n) {
        BigInteger res = new BigInteger("1");
        for(int i = 1; i <= n; i++) {
            res = res.multiply(new BigInteger(Integer.toString(i)));
        }
        return res;
    }
    public static BigInteger comb(int n, int p) {
        BigInteger res = fac(n);
        res = res.divide(fac(n-p));
        res = res.divide(fac(p));
        return res;
    }
    public static void main(String[] args) throws IOException {
        System.out.println(comb(4, 2));
        System.out.println(comb(16, 8));
        System.out.println(comb(100, 50));
        System.out.println(comb(500, 250));
        System.out.println(comb(1000, 500));
        System.out.println(comb(5000, 2500));
        System.out.println(comb(10000, 5000));
        System.out.println(comb(50000, 25000));
        PrintStream ps = new PrintStream(new FileOutputStream("C:\\z.z"));
        ps.println(comb(50000, 25000));
        ps.close();
    }
}
