結果

問題 No.186 中華風 (Easy)
ユーザー gorugo30gorugo30
提出日時 2021-01-30 17:31:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 71,328 KB
最終ジャッジ日時 2023-09-10 13:51:33
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,956 KB
testcase_01 AC 70 ms
71,312 KB
testcase_02 AC 70 ms
71,220 KB
testcase_03 AC 72 ms
71,224 KB
testcase_04 AC 69 ms
71,032 KB
testcase_05 AC 71 ms
71,284 KB
testcase_06 AC 73 ms
71,312 KB
testcase_07 AC 72 ms
71,292 KB
testcase_08 AC 71 ms
71,056 KB
testcase_09 AC 70 ms
71,220 KB
testcase_10 AC 70 ms
71,216 KB
testcase_11 AC 72 ms
71,224 KB
testcase_12 AC 71 ms
71,104 KB
testcase_13 AC 71 ms
71,136 KB
testcase_14 AC 70 ms
71,328 KB
testcase_15 AC 70 ms
71,256 KB
testcase_16 AC 70 ms
71,276 KB
testcase_17 AC 71 ms
71,096 KB
testcase_18 AC 71 ms
71,192 KB
testcase_19 AC 71 ms
71,092 KB
testcase_20 AC 72 ms
71,292 KB
testcase_21 AC 70 ms
71,172 KB
testcase_22 AC 70 ms
71,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b == 0:
        return (1, 0, a)
    X, Y, g = extgcd(b, a % b)
    return (Y, X - (a // b) * Y, g)

def chineserem(B, M):
    r = 0
    ALLM = 1
    for i in range(len(B)):
        x, y, g = extgcd(ALLM, M[i])
        if (B[i] - r) % g != 0:
            return (-1, -1)
        r += ((((B[i] - r) // g) * x) % (M[i] // g)) * ALLM
        ALLM *= (M[i] // g)
    return (r % ALLM, ALLM)

B = []
M = []
for i in range(3):
    x, y = map(int, input().split())
    B.append(x)
    M.append(y)
if max(B) == 0:
    print(chineserem(B, M)[1])
else:
    print(chineserem(B, M)[0])
0