-
Notifications
You must be signed in to change notification settings - Fork 0
/
다리 놓기.java
23 lines (22 loc) · 1.15 KB
/
다리 놓기.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.IntStream;
public class Main{
public static void main(String[] args) throws IOException{
new Main().solution();
}
private void solution() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(br.readLine());
for(int i = 0; i < n; i++){
int[] x = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
BigInteger facN = IntStream.rangeClosed(1, x[1]).mapToObj(BigInteger::valueOf).reduce(BigInteger.ONE, (acc, cur) -> acc.multiply(cur));
BigInteger facM = IntStream.rangeClosed(1, x[0]).mapToObj(BigInteger::valueOf).reduce(BigInteger.ONE, (acc, cur) -> acc.multiply(cur));
BigInteger facNM = IntStream.rangeClosed(1, x[1] - x[0]).mapToObj(BigInteger::valueOf).reduce(BigInteger.ONE, (acc, cur) -> acc.multiply(cur));
sb.append(facN.divide(facM.multiply(facNM))).append("\n");
}
System.out.println(sb.toString());
}
}