結果

問題 No.187 中華風 (Hard)
ユーザー onexisanonexisan
提出日時 2015-05-21 00:52:14
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 597 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 6,504 KB
実行使用メモリ 12,596 KB
最終ジャッジ日時 2023-09-20 10:27:59
合計ジャッジ時間 5,212 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from fractions import gcd

def inv(a, m):
    b, x, y = m, 1, 0
    while b != 0:
        t = a // b
        a, b = b, a - t * b
        x, y = y, x - t * y
        pass
    return x % m

def CRT(congs):
    x, m = 0, 1
    for y, n in congs:
        g = gcd(m, n)
        if x % g != y % g: return -1, -1
        m //= g; m = gcd(m ** 64, m * n); n //= gcd(m, n)
        x %= m; x += (y - x % n) * inv(m, n) % n * m; m *= n
        pass
    return x, m

mod = 10 ** 9 + 7

n = input()
congs = [map(int, raw_input().split()) for _ in xrange(n)]

ans = CRT(congs)[0]
print -1 if ans == -1 else ans
0