結果

問題 No.186 中華風 (Easy)
ユーザー gorugo30gorugo30
提出日時 2021-01-30 17:29:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 541 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 71,672 KB
最終ジャッジ日時 2023-09-10 13:50:21
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,288 KB
testcase_01 AC 72 ms
71,172 KB
testcase_02 AC 77 ms
71,192 KB
testcase_03 AC 72 ms
71,128 KB
testcase_04 AC 73 ms
70,956 KB
testcase_05 AC 72 ms
71,096 KB
testcase_06 AC 73 ms
71,296 KB
testcase_07 AC 74 ms
71,172 KB
testcase_08 AC 72 ms
71,224 KB
testcase_09 AC 74 ms
71,144 KB
testcase_10 AC 70 ms
71,104 KB
testcase_11 AC 71 ms
71,104 KB
testcase_12 AC 72 ms
71,140 KB
testcase_13 AC 70 ms
71,304 KB
testcase_14 AC 70 ms
71,168 KB
testcase_15 AC 71 ms
71,276 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 73 ms
71,096 KB
testcase_19 AC 73 ms
71,380 KB
testcase_20 AC 72 ms
71,172 KB
testcase_21 AC 72 ms
71,384 KB
testcase_22 AC 72 ms
71,260 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)
print(chineserem(B, M)[0])
0