結果
問題 |
No.2119 一般化百五減算
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:07:50 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 861 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 81,564 KB |
実行使用メモリ | 88,484 KB |
最終ジャッジ日時 | 2025-04-16 00:08:51 |
合計ジャッジ時間 | 4,511 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 TLE * 1 -- * 4 |
ソースコード
import math N = int(input()) M = int(input()) congruences = [] for _ in range(M): B, C = map(int, input().split()) c = C % B congruences.append((B, c)) if M == 0: print("NaN") else: current_a, current_mod = congruences[0][1], congruences[0][0] has_solution = True for i in range(1, M): B_i, c_i = congruences[i] d = math.gcd(current_mod, B_i) if (c_i - current_a) % d != 0: has_solution = False break new_mod = (current_mod // d) * B_i a = current_mod // d b_mod = B_i // d rhs = (c_i - current_a) // d inv = pow(a, -1, b_mod) t0 = (rhs * inv) % b_mod current_a += current_mod * t0 current_mod = new_mod if not has_solution: print("NaN") else: print(current_a if current_a <= N else "NaN")