-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5607.cpp
More file actions
57 lines (54 loc) · 747 Bytes
/
5607.cpp
File metadata and controls
57 lines (54 loc) · 747 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
57
// 5607. 조합
// 2019.07.05
#include <iostream>
using namespace std;
const long long p = 1234567891;
// 거듭제곱 재귀
long long pow(long long x, long long y)
{
long long r = 1;
while (y > 0)
{
if (y % 2)
{
r *= x;
r %= p;
}
x *= x;
x %= p;
y /= 2;
}
return r;
}
int main()
{
long long n, k;
int t;
cin >> t;
for (int i = 1; i <= t; i++)
{
cin >> n >> k;
long long A = 1;
long long B = 1;
// n!
for (long long i = n; i >= 1; i--)
{
A *= i;
A %= p;
}
// k!
for (long long i = k; i >= 1; i--)
{
B *= i;
B %= p;
}
// k! * (n-k)!
for (long long i = n - k; i >= 1; i--)
{
B *= i;
B %= p;
}
cout << "#" << i << " " << (A*pow(B, p - 2)) % p << endl;
}
return 0;
}