結果

問題 No.187 中華風 (Hard)
ユーザー onexisanonexisan
提出日時 2015-05-21 01:11:49
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 6,656 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-09-20 08:34:16
合計ジャッジ時間 12,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
7,740 KB
testcase_01 AC 26 ms
7,844 KB
testcase_02 WA -
testcase_03 AC 814 ms
8,028 KB
testcase_04 AC 752 ms
8,080 KB
testcase_05 AC 751 ms
7,900 KB
testcase_06 AC 756 ms
8,088 KB
testcase_07 AC 755 ms
7,900 KB
testcase_08 AC 819 ms
7,940 KB
testcase_09 AC 821 ms
7,936 KB
testcase_10 AC 821 ms
7,956 KB
testcase_11 AC 753 ms
7,972 KB
testcase_12 AC 753 ms
8,068 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 23 ms
7,808 KB
testcase_18 AC 26 ms
7,704 KB
testcase_19 AC 23 ms
7,804 KB
testcase_20 AC 526 ms
7,920 KB
testcase_21 AC 23 ms
7,828 KB
testcase_22 AC 755 ms
7,944 KB
testcase_23 AC 23 ms
7,732 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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:
        _x, _y, _m, _n = x, y, m, n
        g = gcd(m, n)
        m //= g; l = m * n
        _m = m
        while True:
            t = gcd(m * _m, l)
            if t == m: break
            m = t
        n //= gcd(m, n)
        x %= m; x += (y - x % n) * inv(m, n) % n * m; m *= n
        if x % _m != _x or x % _n != _y: return -1, -1
        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 % mod
0