-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
43 lines (41 loc) · 906 Bytes
/
Copy pathC.cpp
File metadata and controls
43 lines (41 loc) · 906 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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
unordered_map<ll,ll> fact;
#define pii pair<ll,ll>
#define x first
#define y second
const ll mod = 1e9+7,MAX=2e5+1;
void gen(){
fact[1]=1;
for(ll i=2;i<MAX;i++)
fact[i]=(i*fact[i-1])%mod;
}
ll gcd( ll a, ll b ) { return !b ? a : gcd( b, a%b ); }
pii egcd( ll a, ll b ) {
if( b == 0 ) return pii( 1, 0 );
else {
pii d = egcd( b, a % b );
return pii( d.y, d.x - d.y * ( a / b ) );
}
}
ll rev( ll a) {
ll d = gcd( a, mod );
pii ans = egcd( a, mod );
ll ret = ans.x/d, mul = mod/d;
ret %= mul;
if( ret < 0 ) ret += mul;
return ret%mod;
}
int main(){
ios::sync_with_stdio(false);
gen();
int tc;cin>>tc;
while(tc--){
ll N,P;cin>>N>>P;
ll ans = fact[N+P-1];
ans = (ans*rev(fact[N-1]))%mod;
ans = (ans*rev(fact[P]))%mod;
cout<<ans<<endl;
}
}