| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292166 | cnam9 | Slon (COCI15_slon) | Pypy 3 | 289 ms | 72712 KiB |
from __future__ import annotations
def main() -> None:
from dataclasses import dataclass
@dataclass
class Linear:
slope: int
yintercept: int
def __add__(self, other: Linear) -> Linear:
if type(other) == int:
return Linear(self.slope, (self.yintercept + other) % mod)
return Linear((self.slope + other.slope) % mod, (self.yintercept + other.yintercept) % mod)
def __mul__(self, other: Linear) -> Linear:
if type(other) == int:
return Linear(self.slope * other % mod, self.yintercept * other % mod)
return Linear(self.slope * other.slope % mod, (self.yintercept * other.slope + self.slope * other.yintercept) % mod)
def __radd__(self, other: Linear) -> Linear:
if type(other) == int:
return Linear(self.slope, (self.yintercept + other) % mod)
return Linear((self.slope + other.slope) % mod, (self.yintercept + other.yintercept) % mod)
def __rmul__(self, other: Linear) -> Linear:
if type(other) == int:
return Linear(self.slope * other % mod, self.yintercept * other % mod)
return Linear(self.slope * other.slope % mod, (self.yintercept * other.slope + self.slope * other.yintercept) % mod)
x = Linear(1, 0)
expression = input()
value, mod = map(int, input().split())
expression = eval(expression)
if type(expression) == int:
print(0)
return
a = expression.slope
value = (value - expression.yintercept) % mod
from math import gcd
d = gcd(gcd(a, value), mod)
a //= d
value //= d
mod //= d
print(value * pow(a, -1, mod) % mod)
if __name__ == "__main__":
# import sys
# sys.stdin = open("input.txt")
main()Compilation message (stdout)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
