Class BinomialCoefficient

java.lang.Object
org.apache.commons.numbers.combinatorics.BinomialCoefficient

public final class BinomialCoefficient extends Object
Representation of the binomial coefficient. It is "n choose k", the number of k-element subsets that can be selected from an n-element set.
  • Method Details

    • value

      public static long value(int n, int k)
      Computes the binomial coefficient.

      The largest value of n for which all coefficients can fit into a long is 66. Larger n may result in an ArithmeticException depending on the value of k.

      Any min(k, n - k) >= 34 cannot fit into a long and will result in an ArithmeticException.

      Parameters:
      n - Size of the set.
      k - Size of the subsets to be counted.
      Returns:
      n choose k.
      Throws:
      IllegalArgumentException - if n < 0, k < 0 or k > n.
      ArithmeticException - if the result is too large to be represented by a long.