-
Notifications
You must be signed in to change notification settings - Fork 0
/
prob5607.java
44 lines (38 loc) · 1.07 KB
/
prob5607.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
36
37
38
39
40
41
42
43
44
package ComputingThinking;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
//삼성 5607 [Professional] 조합
public class prob5607 {
private static final int MOD = 1234567891;
private static long pow(long bottom) {
long result = 1;
long x = bottom;
int y = MOD-2;
while(y>0) {
if(y%2==1) result = (result*x) % MOD;
y = y/2;
x = (x*x) % MOD;
}
return result;
}
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int test_case = Integer.parseInt(bf.readLine());
for (int i = 1; i <= test_case; i++) {
StringTokenizer st = new StringTokenizer(bf.readLine());
int n = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
long up = 1;
long bottom = 1;
for (int j = n; j > n-r; j--) {
up = (up*j) % MOD;
}
for (int j = 1; j <= r; j++) {
bottom = (bottom*j) % MOD;
}
long result = pow(bottom) % MOD;
System.out.printf("#%d %d\n",i,(up*result)%MOD);
}
}
}