-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombinatoricSelections.java
35 lines (30 loc) · 1.05 KB
/
CombinatoricSelections.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package dev;
import java.math.BigInteger;
public class CombinatoricSelections {
static public BigInteger fac(int n) {
BigInteger result = BigInteger.ONE;
for (int i = 2; i <= n; i++)
result = result.multiply(BigInteger.valueOf(i));
return result;
}
static public BigInteger combinatoricSelections(int n, int r) {
return fac(n).divide(fac(r).multiply(fac(n - r)));
}
public static void main(String[] args) {
long startTime = System.nanoTime();
BigInteger comSel = new BigInteger("0");
int counter = 0;
for (int i = 1; i <= 100; i++) {
for (int j = 1; j <= i; j++) {
comSel = combinatoricSelections(i, j);
if (comSel.compareTo(new BigInteger("1000000")) == 1) {
counter++;
}
}
}
long endTime = System.nanoTime();
long totalTime = (endTime - startTime)/1_000_000;
System.out.println(totalTime + " milliseconds");
System.out.println(counter);
}
}