-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrivals.cpp
More file actions
45 lines (39 loc) · 798 Bytes
/
rivals.cpp
File metadata and controls
45 lines (39 loc) · 798 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
#include <iostream>
// inverse modulo
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;
const int sz = 2*1e6+10;
ll fact[sz];
int xGCD(int a, int b, int &x, int &y) {
if (a == 0) {
x = 0, y = 1;
return b;
}
int x1, y1, gcd = xGCD(b%a, a, x1, y1);
x = y1 - (b/a) * x1;
y = x1;
return gcd;
}
ll mod_inv(int a) {
int x, y;
int g = xGCD(a, mod, x, y);
return (x%mod + mod) % mod;
}
void fib() {
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i < sz; ++i)
fact[i] = (fact[i-1] * (i))%mod;
}
int main() {
freopen("input.txt", "r", stdin);
fib();
int test_cases, x, y;
cin >> test_cases;
while (test_cases--) {
cin >> x >> y;
cout << (fact[x+y] * (mod_inv(fact[x]) * mod_inv(fact[y])%mod)) % mod << endl;
}
return 0;
}