-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmodular_arithmetic.cpp
More file actions
93 lines (88 loc) · 2.07 KB
/
modular_arithmetic.cpp
File metadata and controls
93 lines (88 loc) · 2.07 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long int
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 500001
#define mod 1000000007
struct modint
{
int val;
modint(int v = 0) { val = v % mod; }
int pow(int y)
{
modint x = val;
modint z = 1;
while (y)
{
if (y & 1)
z *= x;
x *= x;
y >>= 1;
}
return z.val;
}
int inv() { return pow(mod - 2); }
void operator=(int o) { val = o % mod; }
void operator=(modint o) { val = o.val % mod; }
void operator+=(modint o) { *this = *this + o; }
void operator-=(modint o) { *this = *this - o; }
void operator*=(modint o) { *this = *this * o; }
void operator/=(modint o) { *this = *this / o; }
bool operator==(modint o) { return val == o.val; }
bool operator!=(modint o) { return val != o.val; }
int operator*(modint o) { return ((val * o.val) % mod); }
int operator/(modint o) { return (val * o.inv()) % mod; }
int operator+(modint o) { return (val + o.val) % mod; }
int operator-(modint o) { return (val - o.val + mod) % mod; }
};
modint f[MAXN];
modint inv[MAXN];
modint invfat[MAXN];
void calc()
{
f[0] = 1;
for (int i = 1; i < MAXN; i++)
{
f[i] = f[i - 1] * i;
}
inv[1] = 1;
for (int i = 2; i < MAXN; ++i)
{
int val = mod / i;
val = (inv[mod % i] * val) % mod;
val = mod - val;
inv[i] = val;
}
invfat[0] = 1;
invfat[MAXN - 1] = modint(f[MAXN - 1]).inv();
for (int i = MAXN - 2; i >= 1; i--)
{
invfat[i] = invfat[i + 1] * (i + 1);
}
}
modint ncr(int n, int k) // combinacao
{
modint ans = f[n] * invfat[k];
ans *= invfat[n - k];
return ans;
}
modint arr(int n, int k) // arranjo
{
modint ans = f[n] * invfat[n - k];
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}