3
3
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
4
4
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
5
5
const int mod = 1000000007 ;
6
+ const int mod = 998244353 ;
6
7
struct mint {
7
8
ll x; // typedef long long ll;
8
9
mint (ll x=0 ):x((x%mod+mod)%mod){}
@@ -15,22 +16,10 @@ struct mint {
15
16
if ((x += mod-a.x ) >= mod) x -= mod;
16
17
return *this ;
17
18
}
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;}
34
23
mint pow (ll t) const {
35
24
if (!t) return 1 ;
36
25
mint a = pow (t>>1 );
@@ -40,14 +29,9 @@ struct mint {
40
29
}
41
30
42
31
// 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