-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11401.cpp
More file actions
36 lines (32 loc) · 870 Bytes
/
11401.cpp
File metadata and controls
36 lines (32 loc) · 870 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
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
long long factorial[4000004];
long long func(int a, int exp){
if(exp==1) return a%mod;
long long half = func(a, exp/2);
long long result = (half*half)%mod;
if(exp%2) result = (result*a)%mod;
return result;
}
int main(){
int n, k; cin>>n>>k;
if(k==0 || n==k){
cout<<"1"<<endl;
return 0;
}
factorial[1]=1;
for(int i=2; i<=4000000; i++)
factorial[i] = (factorial[i-1]*i)%mod;
int top = factorial[n];
int bottom_left = factorial[k];
int bottom_right = factorial[n-k];
long long bottom = (1LL*bottom_left*bottom_right)%mod;
int exp = mod;
//cout<<top<<" "<<bottom<<endl;
long long base = func(bottom, exp-2);
long long result = (top)*(base)%mod;
cout<<result<<endl;
return 0;
}