結果

問題 No.187 中華風 (Hard)
ユーザー fmhrfmhr
提出日時 2015-04-20 13:27:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 435 ms / 3,000 ms
コード長 673 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 78,512 KB
最終ジャッジ日時 2023-09-18 00:51:45
合計ジャッジ時間 7,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,260 KB
testcase_01 AC 90 ms
76,052 KB
testcase_02 AC 145 ms
77,732 KB
testcase_03 AC 136 ms
77,620 KB
testcase_04 AC 407 ms
77,552 KB
testcase_05 AC 408 ms
77,732 KB
testcase_06 AC 407 ms
77,988 KB
testcase_07 AC 408 ms
77,772 KB
testcase_08 AC 433 ms
77,700 KB
testcase_09 AC 429 ms
77,856 KB
testcase_10 AC 435 ms
77,668 KB
testcase_11 AC 389 ms
77,924 KB
testcase_12 AC 409 ms
77,552 KB
testcase_13 AC 96 ms
76,180 KB
testcase_14 AC 90 ms
76,452 KB
testcase_15 AC 137 ms
78,512 KB
testcase_16 AC 131 ms
77,432 KB
testcase_17 AC 71 ms
71,288 KB
testcase_18 AC 87 ms
75,940 KB
testcase_19 AC 72 ms
71,560 KB
testcase_20 AC 311 ms
77,752 KB
testcase_21 AC 73 ms
71,532 KB
testcase_22 AC 408 ms
77,844 KB
testcase_23 AC 74 ms
71,512 KB
testcase_24 AC 71 ms
71,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def egcd(x, y):
    if y == 0:
        return (x, 1, 0)
    (d, a, b) = egcd(y, x % y)
    return (d, b, a - (x // y) * b)

def crt(p, m, q, n):
    a, d, r = egcd(p, q)
    if (n - m) % a != 0:
        return (-1, -1)
    mod = p * (q // a)
    a = (d * ((n - m) // a) * p + m) % mod
    return (a, mod)

def chinese_remainder(items):
    xx = 0
    yy = 1
    for x, y in items:
        xx, yy = crt(y, x, yy, xx)
        if xx == -1:
            print(-1)
            sys.exit(0)
    if xx == 0:
        xx = yy
    return xx

n = int(input())
x = [0] * n
for i in range(n):
    x[i] = tuple(map(int, input().split()))
print(chinese_remainder(x) % (10**9+7))
0