結果

問題 No.186 中華風 (Easy)
ユーザー rlangevinrlangevin
提出日時 2021-12-04 18:09:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 71,632 KB
最終ジャッジ日時 2023-09-21 06:06:07
合計ジャッジ時間 3,299 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,264 KB
testcase_01 AC 74 ms
71,188 KB
testcase_02 AC 79 ms
71,584 KB
testcase_03 AC 74 ms
71,244 KB
testcase_04 AC 76 ms
71,424 KB
testcase_05 AC 77 ms
71,436 KB
testcase_06 AC 76 ms
71,044 KB
testcase_07 AC 76 ms
71,316 KB
testcase_08 AC 77 ms
71,244 KB
testcase_09 AC 79 ms
71,136 KB
testcase_10 AC 78 ms
71,532 KB
testcase_11 AC 76 ms
71,580 KB
testcase_12 AC 76 ms
71,460 KB
testcase_13 AC 76 ms
71,336 KB
testcase_14 AC 76 ms
71,228 KB
testcase_15 AC 75 ms
71,324 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 76 ms
71,532 KB
testcase_19 AC 75 ms
71,492 KB
testcase_20 AC 75 ms
71,040 KB
testcase_21 AC 76 ms
71,372 KB
testcase_22 AC 77 ms
71,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def ChineseRem(b1, b2, m1, m2):
    from math import gcd

    def extGCD(a, b):
        # ax + by = gcd(a, b)の解を求める
        if b == 0:
            return 1, 0
        q = a // b
        r = a % b
        X, Y = extGCD(b, r)
        return Y, X - q * Y

    if (b1 - b2) % gcd(m1, m2) != 0:
        return False, False
    d = gcd(m1, m2)
    lcm = m1 * m2 // d
    p, q = extGCD(m1, m2)
    return ((b2 - b1) // d * m1 * p + b1) % lcm, lcm


X, M = [0] * 3, [0] * 3
for i in range(3):
    X[i], M[i] = map(int, input().split())

x, mod = ChineseRem(X[0], X[1], M[0], M[1])
if not x:
    print(-1)
else:
    ans, _ = ChineseRem(x, X[2], mod, M[2])
    if ans:
        print(ans)
    else:
        print(-1)
0