/
BOJ_1010_new.java
32 lines (29 loc) · 1.1 KB
/
BOJ_1010_new.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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
private void solution() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
while (t-->0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
sb.append(combination(m, n)).append('\n');
}
System.out.print(sb);
}
private String combination(int m, int n) {
n = Math.min(n, m-n);
long nFac = 1l;
for (int i = 2; i <= n; i++) nFac*=i;
BigInteger res = BigInteger.ONE;
while(n-->0) res=res.multiply(new BigInteger(String.valueOf(m--)));
return res.divide(new BigInteger(String.valueOf(nFac))).toString();
}
public static void main(String[] args) throws Exception {
new Main().solution();
}
}