-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnCr_nPr.sublime-snippet
More file actions
46 lines (44 loc) · 1.12 KB
/
nCr_nPr.sublime-snippet
File metadata and controls
46 lines (44 loc) · 1.12 KB
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
<snippet>
<content><![CDATA[
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6, mod = 1e9 + 7;
int power(long long n, long long k) {
int ans = 1 % mod; n %= mod; if (n < 0) n += mod;
while (k) {
if (k & 1) ans = (long long) ans * n % mod;
n = (long long) n * n % mod;
k >>= 1;
}
return ans;
}
int f[N], invf[N];
int nCr(int n, int r) {
if (n < r or n < 0) return 0;
return 1LL * f[n] * invf[r] % mod * invf[n - r] % mod;
}
int nPr(int n, int r) {
if (n < r or n < 0) return 0;
return 1LL * f[n] * invf[n - r] % mod;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
f[0] = 1;
for (int i = 1; i < N; i++) {
f[i] = 1LL * i * f[i - 1] % mod;
}
invf[N - 1] = power(f[N - 1], mod - 2);
for (int i = N - 2; i >= 0; i--) {
invf[i] = 1LL * invf[i + 1] * (i + 1) % mod;
}
cout << nCr(6, 2) << '\n';
cout << nPr(6, 2) << '\n';
return 0;
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>nCr_nPr</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.c++</scope>
</snippet>