結果

問題 No.186 中華風 (Easy)
ユーザー nisizawanisizawa
提出日時 2017-12-16 23:08:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2023-09-27 00:51:09
合計ジャッジ時間 1,748 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,792 KB
testcase_01 AC 16 ms
7,840 KB
testcase_02 AC 16 ms
7,752 KB
testcase_03 AC 15 ms
7,824 KB
testcase_04 AC 16 ms
7,832 KB
testcase_05 AC 16 ms
7,748 KB
testcase_06 AC 16 ms
7,736 KB
testcase_07 AC 16 ms
7,928 KB
testcase_08 AC 15 ms
7,744 KB
testcase_09 AC 15 ms
7,796 KB
testcase_10 AC 15 ms
7,784 KB
testcase_11 AC 16 ms
7,840 KB
testcase_12 AC 16 ms
7,752 KB
testcase_13 AC 15 ms
7,832 KB
testcase_14 AC 16 ms
7,916 KB
testcase_15 AC 16 ms
7,804 KB
testcase_16 AC 16 ms
7,836 KB
testcase_17 AC 16 ms
7,788 KB
testcase_18 AC 16 ms
7,748 KB
testcase_19 AC 16 ms
7,744 KB
testcase_20 AC 16 ms
7,800 KB
testcase_21 AC 17 ms
7,756 KB
testcase_22 AC 16 ms
7,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1

    while c1 > 0:
        q, r = divmod(c0, c1)

        c0, c1 = c1, r
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)

    return c0, a0, b0

def crt(x1, y1, x2, y2):
    gcd, a, b = ex_euclid(y1, y2)
    lcm = y1 * y2 // gcd
    
    c = x2 - x1
    if c % gcd != 0:
        return -1, lcm
    
    n = (y1 * c * a // gcd + x1) % lcm
    return n if n > 0 else lcm, lcm

def solve(x1, y1, x2, y2, x3, y3):
    x12, y12 = crt(x1, y1, x2, y2)
    if x12 < 0:
        return x12
    x123, y123 = crt(x12, y12, x3, y3)
    return x123

x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x3, y3 = map(int, input().split())

print(solve(x1, y1, x2, y2, x3, y3))
0