-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmint.cpp
29 lines (24 loc) · 1.34 KB
/
mint.cpp
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
const int mod = (int) 998244353;//change the value as needed
struct mint {
int value;
static const int MOD_value = mod;
mint(long long v = 0) { value = v % mod; if (value < 0) value += mod;}
mint(long long a, long long b) : value(0){ *this += a; *this /= b;}
mint& operator+=(mint const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
mint& operator-=(mint const& b) {value -= b.value; if (value < 0) value += mod; return *this;}
mint& operator*=(mint const& b) {value = (long long)value * b.value % mod; return *this;}
static mint mexp(mint a, long long e) {
mint res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
static mint inverse(mint a) { return mexp(a, mod - 2); }
mint& operator/=(mint const& b) { return *this *= inverse(b); }
friend mint operator+(mint a, mint const b) { return a += b; }
friend mint operator-(mint a, mint const b) { return a -= b; }
friend mint operator-(mint const a) { return 0 - a; }
friend mint operator*(mint a, mint const b) { return a *= b; }
friend mint operator/(mint a, mint const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, mint const& a) {return os << a.value;}
friend bool operator==(mint const& a, mint const& b) {return a.value == b.value;}
friend bool operator!=(mint const& a, mint const& b) {return a.value != b.value;}
};