-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightOj-1102 - Problem Makes Problem.cpp
63 lines (51 loc) · 1.18 KB
/
LightOj-1102 - Problem Makes Problem.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
/// Time-0.667s
/// combinatorics problem and bigmod and fermat's theorem
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mx=2000005;
ll mod=1000000007;
ll fact[mx];
void cal()
{
fact[0]=1ll;
for(int i=1;i<mx;i++)
{
fact[i]=(fact[i-1]*i)%mod;
}
}
ll mod_power(ll a,ll b)
{
ll res=1ll;
while(b)
{
if(b&1ll) res=(res*a)%mod;
a=(a*a)%mod;
b=b>>1ll;
}
return (res%mod);
}
int main()
{
ios::sync_with_stdio(false);
cal();
int t;
ll n,k;
cin>>t;
int caseno=0;
while(t--)
{
caseno++;
/// (n+k-1)! % mod [ numerator]
/// ---------------------------
/// (n! *(k-1)!) %mod [ denominator]
/// According to fermat theorem a^(b-1) % b = 1 ,so a^(-1)%mod = a^(mod-2) %mod=a^(mod-1)%mod *a^(-1) %mod=a^(-1)%mod.
/// (n+k-1)!%mod * (n!*(k-1)!)^(mod-2) %mod
cin>>n>>k;/// n stars and k-1 bars
ll numerator=fact[n+k-1]%mod;
ll denominator=(fact[n]*fact[k-1])%mod;
ll ans=(numerator * mod_power(denominator,mod-2))%mod;
cout<<"Case "<<caseno<<": "<<ans<<endl;
}
return 0;
}