Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7d430ed

Browse files
author
atcoder-live
committed
update mint
・istream,ostreamの演算子オーバーロード ・縦幅を圧縮
1 parent e9d18c8 commit 7d430ed

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

‎mint.cpp‎

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
44
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
55
const int mod = 1000000007;
6+
const int mod = 998244353;
67
struct mint {
78
ll x; // typedef long long ll;
89
mint(ll x=0):x((x%mod+mod)%mod){}
@@ -15,22 +16,10 @@ struct mint {
1516
if ((x += mod-a.x) >= mod) x -= mod;
1617
return *this;
1718
}
18-
mint& operator*=(const mint a) {
19-
(x *= a.x) %= mod;
20-
return *this;
21-
}
22-
mint operator+(const mint a) const {
23-
mint res(*this);
24-
return res+=a;
25-
}
26-
mint operator-(const mint a) const {
27-
mint res(*this);
28-
return res-=a;
29-
}
30-
mint operator*(const mint a) const {
31-
mint res(*this);
32-
return res*=a;
33-
}
19+
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
20+
mint operator+(const mint a) const { return mint(*this) += a;}
21+
mint operator-(const mint a) const { return mint(*this) -= a;}
22+
mint operator*(const mint a) const { return mint(*this) *= a;}
3423
mint pow(ll t) const {
3524
if (!t) return 1;
3625
mint a = pow(t>>1);
@@ -40,14 +29,9 @@ struct mint {
4029
}
4130

4231
// for prime mod
43-
mint inv() const {
44-
return pow(mod-2);
45-
}
46-
mint& operator/=(const mint a) {
47-
return (*this) *= a.inv();
48-
}
49-
mint operator/(const mint a) const {
50-
mint res(*this);
51-
return res/=a;
52-
}
53-
};
32+
mint inv() const { return pow(mod-2);}
33+
mint& operator/=(const mint a) { return *this *= a.inv();}
34+
mint operator/(const mint a) const { return mint(*this) /= a;}
35+
};
36+
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
37+
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /