-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc11401.cpp
More file actions
32 lines (29 loc) · 735 Bytes
/
Copy pathicpc11401.cpp
File metadata and controls
32 lines (29 loc) · 735 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
#include <algorithm>
#include <iostream>
using namespace std;
using lint = long long int;
int getInverseModulo(int k, const int m) {
if (k == 1) return 1;
int p = m - 2;
lint inverse = 1;
while (p) {
if (p & 1) inverse = inverse * k % m;
k = (lint)k * k % m;
p >>= 1;
}
return (int)inverse;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
const int MOD = 1000000007;
int n, k, answer = 1;
cin >> n >> k;
k = min(k, n - k);
for (int i = n; i > n - k; i--) answer = (lint)answer * i % MOD;
for (int i = 1; i <= k; i++)
answer = (lint)answer * getInverseModulo(i, MOD) % MOD;
cout << answer;
return 0;
}