Source code for titan_pylib.math.mod_int_998244353
1from typing import Union
2
3_titan_pylib_ModInt998244353_MOD = 998244353
4
5
[docs]
6class ModInt998244353:
7
8 __slots__ = "val"
9
10 @staticmethod
11 def _inv(a: int) -> int:
12 res = a % _titan_pylib_ModInt998244353_MOD
13 a = a * a % _titan_pylib_ModInt998244353_MOD
14 res = res * a % _titan_pylib_ModInt998244353_MOD
15 a = a * a % _titan_pylib_ModInt998244353_MOD
16 res = res * a % _titan_pylib_ModInt998244353_MOD
17 a = a * a % _titan_pylib_ModInt998244353_MOD
18 res = res * a % _titan_pylib_ModInt998244353_MOD
19 a = a * a % _titan_pylib_ModInt998244353_MOD
20 res = res * a % _titan_pylib_ModInt998244353_MOD
21 a = a * a % _titan_pylib_ModInt998244353_MOD
22 res = res * a % _titan_pylib_ModInt998244353_MOD
23 a = a * a % _titan_pylib_ModInt998244353_MOD
24 res = res * a % _titan_pylib_ModInt998244353_MOD
25 a = a * a % _titan_pylib_ModInt998244353_MOD
26 res = res * a % _titan_pylib_ModInt998244353_MOD
27 a = a * a % _titan_pylib_ModInt998244353_MOD
28 res = res * a % _titan_pylib_ModInt998244353_MOD
29 a = a * a % _titan_pylib_ModInt998244353_MOD
30 res = res * a % _titan_pylib_ModInt998244353_MOD
31 a = a * a % _titan_pylib_ModInt998244353_MOD
32 res = res * a % _titan_pylib_ModInt998244353_MOD
33 a = a * a % _titan_pylib_ModInt998244353_MOD
34 res = res * a % _titan_pylib_ModInt998244353_MOD
35 a = a * a % _titan_pylib_ModInt998244353_MOD
36 res = res * a % _titan_pylib_ModInt998244353_MOD
37 a = a * a % _titan_pylib_ModInt998244353_MOD
38 res = res * a % _titan_pylib_ModInt998244353_MOD
39 a = a * a % _titan_pylib_ModInt998244353_MOD
40 res = res * a % _titan_pylib_ModInt998244353_MOD
41 a = a * a % _titan_pylib_ModInt998244353_MOD
42 res = res * a % _titan_pylib_ModInt998244353_MOD
43 a = a * a % _titan_pylib_ModInt998244353_MOD
44 res = res * a % _titan_pylib_ModInt998244353_MOD
45 a = a * a % _titan_pylib_ModInt998244353_MOD
46 res = res * a % _titan_pylib_ModInt998244353_MOD
47 a = a * a % _titan_pylib_ModInt998244353_MOD
48 res = res * a % _titan_pylib_ModInt998244353_MOD
49 a = a * a % _titan_pylib_ModInt998244353_MOD
50 res = res * a % _titan_pylib_ModInt998244353_MOD
51 a = a * a % _titan_pylib_ModInt998244353_MOD
52 res = res * a % _titan_pylib_ModInt998244353_MOD
53 a = a * a % _titan_pylib_ModInt998244353_MOD
54 res = res * a % _titan_pylib_ModInt998244353_MOD
55 a = a * a % _titan_pylib_ModInt998244353_MOD
56 res = res * a % _titan_pylib_ModInt998244353_MOD
57 a = a * a % _titan_pylib_ModInt998244353_MOD
58 a = a * a % _titan_pylib_ModInt998244353_MOD
59 res = res * a % _titan_pylib_ModInt998244353_MOD
60 a = a * a % _titan_pylib_ModInt998244353_MOD
61 res = res * a % _titan_pylib_ModInt998244353_MOD
62 a = a * a % _titan_pylib_ModInt998244353_MOD
63 a = a * a % _titan_pylib_ModInt998244353_MOD
64 res = res * a % _titan_pylib_ModInt998244353_MOD
65 a = a * a % _titan_pylib_ModInt998244353_MOD
66 res = res * a % _titan_pylib_ModInt998244353_MOD
67 a = a * a % _titan_pylib_ModInt998244353_MOD
68 res = res * a % _titan_pylib_ModInt998244353_MOD
69 return res
70
[docs]
71 @staticmethod
72 def get_mod() -> int:
73 return _titan_pylib_ModInt998244353_MOD
74
75 def __init__(self, val: int) -> None:
76 self.val = (
77 val
78 if 0 <= val < _titan_pylib_ModInt998244353_MOD
79 else val % _titan_pylib_ModInt998244353_MOD
80 )
81
82 def __add__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
83 return ModInt998244353(self.val + int(other))
84
85 def __sub__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
86 return ModInt998244353(self.val - int(other))
87
88 def __mul__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
89 return ModInt998244353(self.val * int(other))
90
91 def __pow__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
92 return ModInt998244353(
93 pow(self.val, int(other), _titan_pylib_ModInt998244353_MOD)
94 )
95
96 def __truediv__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
97 return ModInt998244353(self.val * (self._inv(int(other))))
98
99 __iadd__ = __add__
100 __isub__ = __sub__
101 __imul__ = __mul__
102 __ipow__ = __pow__
103 __itruediv__ = __truediv__
104
105 # def __iadd__(self, other: Union[int, 'ModInt998244353']) -> 'ModInt998244353':
106 # self.val += int(other)
107 # self.val %= _titan_pylib_ModInt998244353_MOD
108 # return self
109
110 # def __isub__(self, other: Union[int, 'ModInt998244353']) -> 'ModInt998244353':
111 # self.val -= int(other)
112 # self.val %= _titan_pylib_ModInt998244353_MOD
113 # return self
114
115 # def __imul__(self, other: Union[int, 'ModInt998244353']) -> 'ModInt998244353':
116 # self.val *= int(other)
117 # self.val %= _titan_pylib_ModInt998244353_MOD
118 # return self
119
120 # def __ipow__(self, other: Union[int, 'ModInt998244353']) -> 'ModInt998244353':
121 # self.val = pow(self.val, int(other), _titan_pylib_ModInt998244353_MOD)
122 # return self
123
124 # def __itruediv__(self, other: Union[int, 'ModInt998244353']) -> 'ModInt998244353':
125 # self.val *= self._inv(int(other))
126 # self.val %= _titan_pylib_ModInt998244353_MOD
127 # return self
128
129 __radd__ = __add__
130 __rmul__ = __mul__
131
132 def __rsub__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
133 return ModInt998244353(int(other) - self.val)
134
135 def __rpow__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
136 return ModInt998244353(
137 pow(int(other), self.val, _titan_pylib_ModInt998244353_MOD)
138 )
139
140 def __rtruediv__(self, other: Union[int, "ModInt998244353"]) -> "ModInt998244353":
141 return ModInt998244353(int(other) * self._inv(self.val))
142
143 def __eq__(self, other: Union[int, "ModInt998244353"]) -> bool:
144 return self.val == int(other)
145
146 def __lt__(self, other: Union[int, "ModInt998244353"]) -> bool:
147 return self.val < int(other)
148
149 def __le__(self, other: Union[int, "ModInt998244353"]) -> bool:
150 return self.val <= int(other)
151
152 def __gt__(self, other: Union[int, "ModInt998244353"]) -> bool:
153 return self.val > int(other)
154
155 def __ge__(self, other: Union[int, "ModInt998244353"]) -> bool:
156 return self.val >= int(other)
157
158 def __ne__(self, other: Union[int, "ModInt998244353"]) -> bool:
159 return self.val != int(other)
160
161 def __neg__(self) -> "ModInt998244353":
162 return ModInt998244353(-self.val)
163
164 def __pos__(self) -> "ModInt998244353":
165 return ModInt998244353(self.val)
166
167 def __int__(self) -> int:
168 return self.val
169
170 def __str__(self) -> str:
171 return str(self.val)
172
173 def __repr__(self):
174 # return f'ModInt998244353({self})'
175 return f"{self}"