Submission #1292166

#TimeUsernameProblemLanguageResultExecution timeMemory
1292166cnam9Slon (COCI15_slon)Pypy 3
12 / 120
289 ms72712 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)

Compiling 'slon.py'...

=======
  adding: __main__.pyc (deflated 58%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...