結果

問題 No.186 中華風 (Easy)
ユーザー shinnshinnshinnshinn
提出日時 2022-03-02 14:54:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,332 KB
最終ジャッジ日時 2023-09-23 08:12:44
合計ジャッジ時間 1,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,304 KB
testcase_01 AC 17 ms
7,820 KB
testcase_02 AC 16 ms
7,888 KB
testcase_03 AC 17 ms
7,848 KB
testcase_04 AC 16 ms
7,824 KB
testcase_05 AC 17 ms
7,768 KB
testcase_06 AC 16 ms
7,948 KB
testcase_07 AC 17 ms
7,892 KB
testcase_08 AC 16 ms
7,892 KB
testcase_09 AC 16 ms
7,912 KB
testcase_10 AC 16 ms
8,168 KB
testcase_11 AC 16 ms
7,904 KB
testcase_12 AC 17 ms
7,916 KB
testcase_13 AC 16 ms
7,848 KB
testcase_14 AC 17 ms
7,796 KB
testcase_15 AC 17 ms
7,788 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
7,888 KB
testcase_19 AC 16 ms
8,332 KB
testcase_20 AC 17 ms
8,208 KB
testcase_21 AC 16 ms
8,160 KB
testcase_22 AC 16 ms
8,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def extgcd(a, b):
    #拡張ユークリッド互除法
    #ax + by = gcd(a, b)となる(x, y)を求めます
    if b == 0:
        return [1, 0]

    q = a//b
    r = a%b
    
    s, t = extgcd(b, r)
    y = s - q*t
    return [t, y]

def CRT(b, m):
    r = 0
    M = 1
    for i in range(len(b)):
        d = gcd(M, m[i])
        p, q = extgcd(M, m[i])

        if (b[i] - r)%d != 0:
            print(-1)
            exit(0)

        t = (b[i] - r)//d * p % (m[i]//d)
        r += M * t
        M *= m[i]//d
    
    return r%M

x = []
y = []
for i in range(3):
    X, Y = map(int, input().split())
    x.append(X)
    y.append(Y)

print(CRT(x, y))
0