Skip to content

Commit 9170147

Browse files
Create mint.cpp
1 parent d264ba5 commit 9170147

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

mint.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const int mod = (int) 998244353;
2+
3+
struct mint {
4+
int value;
5+
static const int MOD_value = mod;
6+
7+
mint(long long v = 0) { value = v % mod; if (value < 0) value += mod;}
8+
mint(long long a, long long b) : value(0){ *this += a; *this /= b;}
9+
10+
mint& operator+=(mint const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
11+
mint& operator-=(mint const& b) {value -= b.value; if (value < 0) value += mod; return *this;}
12+
mint& operator*=(mint const& b) {value = (long long)value * b.value % mod; return *this;}
13+
14+
static mint mexp(mint a, long long e) {
15+
mint res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
16+
return res;
17+
}
18+
static mint inverse(mint a) { return mexp(a, mod - 2); }
19+
20+
mint& operator/=(mint const& b) { return *this *= inverse(b); }
21+
friend mint operator+(mint a, mint const b) { return a += b; }
22+
friend mint operator-(mint a, mint const b) { return a -= b; }
23+
friend mint operator-(mint const a) { return 0 - a; }
24+
friend mint operator*(mint a, mint const b) { return a *= b; }
25+
friend mint operator/(mint a, mint const b) { return a /= b; }
26+
friend std::ostream& operator<<(std::ostream& os, mint const& a) {return os << a.value;}
27+
friend bool operator==(mint const& a, mint const& b) {return a.value == b.value;}
28+
friend bool operator!=(mint const& a, mint const& b) {return a.value != b.value;}
29+
};

0 commit comments

Comments
 (0)