結果
| 問題 | No.2119 一般化百五減算 |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:06:15 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 861 bytes |
| 記録 | |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 96,192 KB |
| 実行使用メモリ | 91,396 KB |
| 最終ジャッジ日時 | 2026-07-09 08:21:10 |
| 合計ジャッジ時間 | 10,592 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 TLE * 2 -- * 1 |
ソースコード
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")
lam6er