結果
問題 | No.2119 一般化百五減算 |
ユーザー |
|
提出日時 | 2022-11-04 21:43:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 813 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 25,472 KB |
最終ジャッジ日時 | 2024-07-18 19:26:16 |
合計ジャッジ時間 | 4,495 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 WA * 4 TLE * 1 -- * 4 |
ソースコード
import sysinput = sys.stdin.buffer.readline"""中国剰余定理 https://tjkendev.github.io/procon-library/python/math/chinese-remainder.html から拝借し、一部改変しています"""def extgcd(a, b):if b:d, y, x = extgcd(b, a % b)y -= (a // b) * xreturn d, x, yreturn a, 1, 0# V = [(X_i, Y_i), ...]: X_i (mod Y_i)def remainder(V):x = 0d = 1for X, Y in V:g, a, b = extgcd(d, Y)x, d = (Y * b * x + d * a * X) // g, d * (Y // g)x %= dreturn xdef solve(V):res = remainder(V)for c, b in V:if res % b != c:return "NaN"return resN = int(input())M = int(input())V = []for _ in range(M):b, c = map(int, input().split())c %= bV.append((c, b))print(solve(V))