結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,520 KB
testcase_01 AC 71 ms
71,412 KB
testcase_02 AC 73 ms
71,420 KB
testcase_03 AC 71 ms
71,516 KB
testcase_04 AC 72 ms
71,420 KB
testcase_05 AC 72 ms
71,472 KB
testcase_06 AC 72 ms
71,352 KB
testcase_07 AC 71 ms
71,280 KB
testcase_08 AC 71 ms
71,328 KB
testcase_09 AC 72 ms
71,328 KB
testcase_10 AC 72 ms
71,080 KB
testcase_11 AC 73 ms
71,076 KB
testcase_12 AC 72 ms
71,420 KB
testcase_13 AC 71 ms
71,604 KB
testcase_14 AC 73 ms
71,440 KB
testcase_15 AC 70 ms
71,520 KB
testcase_16 AC 72 ms
71,560 KB
testcase_17 AC 72 ms
71,320 KB
testcase_18 AC 72 ms
71,292 KB
testcase_19 AC 72 ms
71,288 KB
testcase_20 AC 71 ms
71,416 KB
testcase_21 AC 71 ms
71,444 KB
testcase_22 AC 70 ms
71,436 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 += ( (x * (B[i] - r) // g) % (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