Skip to content

Commit 0c2849d

Browse files
hidehic0github-actions[bot]
authored andcommitted
Merge split file by actions
1 parent d8be03f commit 0c2849d

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

code/main.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,81 @@ def check(mid:int):
177177
right = mid
178178

179179
return left
180+
def mod_add(a: int, b: int, mod: int):
181+
return (a + b) % mod
182+
183+
184+
def mod_sub(a: int, b: int, mod: int):
185+
return (a - b) % mod
186+
187+
188+
def mod_mul(a: int, b: int, mod: int):
189+
return (a * b) % mod
190+
191+
192+
def mod_div(a: int, b: int, mod: int):
193+
return (a * pow(b, mod - 2, mod)) % mod
194+
195+
196+
class ModInt:
197+
def __init__(self, x: int, mod: int = 998244353) -> None:
198+
self.x = x % mod
199+
self.mod = mod
200+
201+
def val(self):
202+
return self.x
203+
204+
def rhs(self, rhs) -> int:
205+
return rhs.x if isinstance(rhs, ModInt) else rhs
206+
207+
def __add__(self, rhs) -> int:
208+
return mod_add(self.x, self.rhs(rhs), self.mod)
209+
210+
def __iadd__(self, rhs) -> "ModInt":
211+
self.x = self.__add__(rhs)
212+
213+
return self
214+
215+
def __sub__(self, rhs) -> int:
216+
return mod_sub(self.x, self.rhs(rhs), self.mod)
217+
218+
def __isub__(self, rhs) -> "ModInt":
219+
self.x = self.__sub__(rhs)
220+
221+
return self
222+
223+
def __mul__(self, rhs):
224+
return mod_mul(self.x, self.rhs(rhs), self.mod)
225+
226+
def __imul__(self, rhs):
227+
self.x = self.__mul__(rhs)
228+
229+
return self
230+
231+
def __truediv__(self, rhs):
232+
return mod_div(self.x, self.rhs(rhs), self.mod)
233+
234+
def __itruediv__(self, rhs):
235+
self.x = self.__truediv__(rhs)
236+
237+
return self
238+
239+
def __floordiv__(self, rhs):
240+
return (self.x // self.rhs(rhs)) % self.mod
241+
242+
def __ifloordiv__(self, rhs):
243+
self.x = self.__floordiv__(rhs)
244+
245+
return self
246+
247+
def __pow__(self, rhs):
248+
return pow(self.x, self.rhs(rhs), self.mod)
249+
250+
def __eq__(self, rhs) -> bool:
251+
return self.rhs(rhs) == self.x
252+
253+
def __ne__(self, rhs) -> bool:
254+
return self.rhs(rhs) != self.x
180255
# 標準入力関数
181256
import sys
182257

0 commit comments

Comments
 (0)