結果

問題 No.186 中華風 (Easy)
ユーザー AEnAEn
提出日時 2023-06-04 22:32:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 603 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 71,688 KB
最終ジャッジ日時 2023-08-28 08:32:46
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,032 KB
testcase_01 AC 68 ms
71,108 KB
testcase_02 AC 69 ms
71,172 KB
testcase_03 AC 70 ms
71,088 KB
testcase_04 AC 70 ms
71,012 KB
testcase_05 AC 70 ms
71,208 KB
testcase_06 AC 70 ms
71,128 KB
testcase_07 AC 70 ms
70,820 KB
testcase_08 AC 68 ms
70,828 KB
testcase_09 AC 69 ms
71,128 KB
testcase_10 AC 68 ms
71,128 KB
testcase_11 AC 70 ms
71,028 KB
testcase_12 AC 68 ms
70,824 KB
testcase_13 AC 68 ms
71,128 KB
testcase_14 AC 67 ms
71,056 KB
testcase_15 AC 69 ms
71,164 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 69 ms
71,032 KB
testcase_19 AC 68 ms
71,016 KB
testcase_20 AC 68 ms
70,960 KB
testcase_21 AC 69 ms
71,108 KB
testcase_22 AC 71 ms
71,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    """returns gcd(a, b), s, r s.t. a * s + b * r == gcd(a, b)"""
    s, bs = 0, 1
    r, br = b, a
    while r:
        q = br // r
        br, r = r, br - q * r
        bs, s = s, bs - q * s
    return br, bs, (br-bs*a)//b if b else 0

def crt(V):
    """最小のxと最小公倍数dを返す"""
    x = 0; d = 1
    for X, Y in V:
        g, a, b = extgcd(d, Y)
        x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
        x %= d
    return x, d

a = [list(map(int, input().split())) for _ in range(3)]
x,d = crt(a)
for X,Y in a:
    if x%Y!=X:
        print(-1)
        exit()
print(x)
0