-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarth_vader.cpp
64 lines (47 loc) · 1.06 KB
/
darth_vader.cpp
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
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
ll fact[200010];
ll pwr(ll b, ll p) {
if (p == 0)
return 1;
ll x = pwr(b, p / 2);
x = (x * x) % mod;
if (p % 2 == 0)
return x;
else
return (b * x) % mod;
}
int main() {
ll cs, t, i, j, k, x1, y1, x2, y2, z, ans, q, m, x, y;
fact[0] = 1;
for (i = 1; i <= 200001; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
cin >> t;
for (cs = 1; cs <= t; cs++) {
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
x = x2 - x1;
y = y2 - y1;
z = 0;
// cout<<z<<endl;
for (i = 0; i <= min(x, y); i++) {
k = 1;
k = (k * ((((fact[x + y - i] * pwr(fact[x], mod - 2)) % mod) *
pwr(fact[y - i], mod - 2)) %
mod)) %
mod; // k=k*ncr(x+y-i,x)
k = (k * ((((fact[x] * pwr(fact[i], mod - 2)) % mod) *
pwr(fact[x - i], mod - 2)) %
mod)) %
mod; // k=k*ncr(x,i)
z = (z + k) % mod;
}
printf("Case%lld:%lld\n", cs, z);
}
return 0;
}