結果

問題 No.187 中華風 (Hard)
ユーザー hly1204hly1204
提出日時 2021-05-08 09:45:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 905 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-10-14 12:45:39
合計ジャッジ時間 1,529 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,248 KB
testcase_01 AC 14 ms
8,260 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 13 ms
8,284 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: UTF-8 -*-

def exgcd(a: int, b: int) -> (int, int, int):
    # 返回 (gcd(a,b), x, y) 满足 gcd(a,b)=ax+by
    x1, x2, x3, x4 = 1, 0, 0, 1
    while b != 0:
        q = a // b
        x1, x2, x3, x4, a, b = x3, x4, x1 - x3 * q, x2 - x4 * q, b, a - b * q
    return a, x1, x2


def gcrt2(a: int, m1: int, b: int, m2: int) -> (int, int):
    d, x, y = exgcd(m1, m2)
    bma = b - a
    if bma % d != 0:
        return -1, -1
    t, y = m2 // d, bma // d
    res = x * y % t
    if res < 0:
        res += t
    return res * m1 + a, m1 * t

if __name__ == '__main__':
    n = int(input())
    ans, m0 = 0, 1
    for _ in range(0, n):
        d, c = (int(i) for i in input().split(' '))
        ans, m0 = gcrt2(ans, m0, c, d)
        if ans == -1:
            break
    if ans == -1:
        print(-1)
    elif ans == 0:
        print(m0 % 1000000007)
    else:
        print(ans % 1000000007)
0