public final class BinomialCoefficient extends Object
n choose k
", the number of k
-element subsets that
can be selected from an n
-element set.Modifier and Type | Method and Description |
---|---|
static long |
value(int n,
int k)
Computes the binomial coefficient.
|
public static long value(int n, int k)
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
.
n
- Size of the set.k
- Size of the subsets to be counted.n choose k
.IllegalArgumentException
- if n < 0
, k < 0
or k > n
.ArithmeticException
- if the result is too large to be
represented by a long
.Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.