結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-04 10:36:47 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,059 bytes |
| コンパイル時間 | 285 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-17 20:44:05 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
コンパイルメッセージ
Main.py:10: SyntaxWarning: invalid escape sequence '\e' '''
ソースコード
def extended_euclid(a, b):
x1, y1, m = 1, 0, a
x2, y2, n = 0, 1, b
while m % n != 0:
q, r = divmod(m, n)
x1, y1, m, x2, y2, n = x2, y2, n, x1 - q * x2, y1 - q * y2, r
return (x2, y2, n)
def chinese_reminder(A, M):
'''
solve
x \equiv a_1 (mod m_1), ... x \equiv a_k (mod m_k)
by applying the Chinese reminder theorem
Input:
A = [a_1, ..., a_k]: a list
M = [m_1, ..., m_k]: a list.
Output:
Returns the tuple (x, mod) of the solution x and the modulus mod = m_1 ... m_k if exists
else (0, -1).
'''
# initialize
x = 0
mod = 1
for a, m in zip(A, M):
u, v, g = extended_euclid(mod, m)
q, r = divmod(a - x, g)
if r != 0:
return (0, -1)
x += q * mod * u
mod *= m // g
x %= mod
return (x, mod)
A = []
M = []
for _ in range(3):
a, m = map(int, input().split())
A.append(a)
M.append(m)
x, m = chinese_reminder(A, M)
print(x if m != -1 else -1)