-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmint.cpp
More file actions
126 lines (97 loc) · 2.59 KB
/
Copy pathmint.cpp
File metadata and controls
126 lines (97 loc) · 2.59 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template<int M>
struct static_mint {
static_assert(0 < M, "Module must be positive");
int val;
constexpr static_mint() : val() {}
constexpr static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
constexpr static_mint pow(long long n) const {
static_mint ans = 1, x(*this);
for (; n > 0; n /= 2) {
if (n & 1) ans *= x;
x *= x;
}
return ans;
}
constexpr static_mint inv() const {
return pow(M - 2);
}
constexpr static_mint operator+() const {
static_mint m;
m.val = val;
return m;
}
constexpr static_mint operator-() const {
static_mint m;
m.val = (val == 0 ? 0 : M - val);
return m;
}
constexpr static_mint &operator+=(const static_mint &m) {
if ((val += m.val) >= M) val -= M;
return *this;
}
constexpr static_mint &operator-=(const static_mint &m) {
if ((val -= m.val) < 0) val += M;
return *this;
}
constexpr static_mint &operator*=(const static_mint &m) {
val = (long long) val * m.val % M;
return *this;
}
constexpr static_mint &operator/=(const static_mint &m) {
val = (long long) val * m.inv().val % M;
return *this;
}
constexpr friend static_mint operator+(const static_mint &lhs, const static_mint &rhs) {
return static_mint(lhs) += rhs;
}
constexpr friend static_mint operator-(const static_mint &lhs, const static_mint &rhs) {
return static_mint(lhs) -= rhs;
}
constexpr friend static_mint operator*(const static_mint &lhs, const static_mint &rhs) {
return static_mint(lhs) *= rhs;
}
constexpr friend static_mint operator/(const static_mint &lhs, const static_mint &rhs) {
return static_mint(lhs) /= rhs;
}
constexpr friend bool operator==(const static_mint &lhs, const static_mint &rhs) {
return lhs.val == rhs.val;
}
constexpr friend bool operator!=(const static_mint &lhs, const static_mint &rhs) {
return lhs.val != rhs.val;
}
constexpr static_mint &operator++() {
return *this += 1;
}
constexpr static_mint &operator--() {
return *this -= 1;
}
constexpr static_mint operator++(int) {
static_mint result(*this);
*this += 1;
return result;
}
constexpr static_mint operator--(int) {
static_mint result(*this);
*this -= 1;
return result;
}
template<typename T>
constexpr explicit operator T() const {
return T(val);
}
friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
return os << m.val;
}
friend std::istream &operator>>(std::istream &is, static_mint &m) {
long long x;
return is >> x, m = x, is;
}
};
using mint = static_mint<mod>;
int main() {
cout << "Hello World\n";
return 0;
}