結果

問題 No.186 中華風 (Easy)
ユーザー rlangevinrlangevin
提出日時 2021-12-04 18:14:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 71,572 KB
最終ジャッジ日時 2023-09-21 06:11:31
合計ジャッジ時間 3,419 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,048 KB
testcase_01 AC 75 ms
71,172 KB
testcase_02 AC 77 ms
71,472 KB
testcase_03 AC 76 ms
71,428 KB
testcase_04 AC 77 ms
71,412 KB
testcase_05 AC 77 ms
71,416 KB
testcase_06 AC 76 ms
71,112 KB
testcase_07 AC 77 ms
71,348 KB
testcase_08 AC 76 ms
71,244 KB
testcase_09 AC 75 ms
71,056 KB
testcase_10 AC 78 ms
71,156 KB
testcase_11 AC 77 ms
71,348 KB
testcase_12 AC 75 ms
71,292 KB
testcase_13 AC 76 ms
71,428 KB
testcase_14 AC 76 ms
71,248 KB
testcase_15 AC 74 ms
71,052 KB
testcase_16 AC 75 ms
71,224 KB
testcase_17 AC 75 ms
71,232 KB
testcase_18 AC 76 ms
71,424 KB
testcase_19 AC 77 ms
71,572 KB
testcase_20 AC 75 ms
71,348 KB
testcase_21 AC 75 ms
71,416 KB
testcase_22 AC 76 ms
71,428 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 None, None
    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 x is None:
    print(-1)
else:
    ans, lcm = ChineseRem(x, X[2], mod, M[2])
    if ans is None:
        print(-1)
    else:
        if ans == 0:
            print(lcm)
        else:
            print(ans)
0