結果
| 問題 |
No.2119 一般化百五減算
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:04:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 861 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 82,028 KB |
| 実行使用メモリ | 88,448 KB |
| 最終ジャッジ日時 | 2025-04-16 00:06:06 |
| 合計ジャッジ時間 | 4,886 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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")
lam6er