@Test public void testBinomial() { assertEquals(new BigInteger("1"), Library.binomial(0, 0)); assertEquals(new BigInteger("1"), Library.binomial(1, 0)); assertEquals(new BigInteger("1"), Library.binomial(1, 1)); assertEquals(new BigInteger("1"), Library.binomial(2, 0)); assertEquals(new BigInteger("2"), Library.binomial(2, 1)); assertEquals(new BigInteger("1"), Library.binomial(2, 2)); assertEquals(new BigInteger("1"), Library.binomial(3, 0)); assertEquals(new BigInteger("3"), Library.binomial(3, 1)); assertEquals(new BigInteger("3"), Library.binomial(3, 2)); assertEquals(new BigInteger("1"), Library.binomial(3, 3)); assertEquals(new BigInteger("35"), Library.binomial(7, 4)); assertEquals(new BigInteger("120"), Library.binomial(10, 7)); assertEquals(new BigInteger("21"), Library.binomial(21, 20)); assertEquals(new BigInteger("88749815264600"), Library.binomial(50, 28)); }
public static BigInteger binomial(int n, int k) { if (k < 0 || k > n) throw new IllegalArgumentException(); BigInteger product = BigInteger.ONE; for (int i = 0; i < k; i++) product = product.multiply(BigInteger.valueOf(n - i)); return product.divide(factorial(k)); }
Library { public static BigInteger binomial(int n, int k) { if (k < 0 || k > n) throw new IllegalArgumentException(); BigInteger product = BigInteger.ONE; for (int i = 0; i < k; i++) product = product.multiply(BigInteger.valueOf(n - i)); return product.divide(factorial(k)); } }
Library { public static BigInteger binomial(int n, int k) { if (k < 0 || k > n) throw new IllegalArgumentException(); BigInteger product = BigInteger.ONE; for (int i = 0; i < k; i++) product = product.multiply(BigInteger.valueOf(n - i)); return product.divide(factorial(k)); }  }
Library { public static BigInteger binomial(int n, int k) { if (k < 0 || k > n) throw new IllegalArgumentException(); BigInteger product = BigInteger.ONE; for (int i = 0; i < k; i++) product = product.multiply(BigInteger.valueOf(n - i)); return product.divide(factorial(k)); }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr); }
Library { public static BigInteger binomial(int n, int k) { if (k < 0 || k > n) throw new IllegalArgumentException(); BigInteger product = BigInteger.ONE; for (int i = 0; i < k; i++) product = product.multiply(BigInteger.valueOf(n - i)); return product.divide(factorial(k)); }  static String reverse(String s); static boolean isPalindrome(String s); static boolean isPalindrome(int x); static int sqrt(int x); static long sqrt(long x); static BigInteger sqrt(BigInteger x); static boolean isSquare(int x); static int pow(int x, int y); static int powMod(int x, int y, int m); static int reciprocalMod(int x, int m); static BigInteger factorial(int n); static BigInteger binomial(int n, int k); static int gcd(int x, int y); static boolean isPrime(int x); static boolean[] listPrimality(int n); static int[] listPrimes(int n); static int[] listSmallestPrimeFactors(int n); static int totient(int n); static int[] listTotients(int n); static boolean nextPermutation(int[] arr);  }