結果

問題 No.187 中華風 (Hard)
ユーザー tjaketjake
提出日時 2017-01-02 16:42:15
言語 Python2
(2.7.18)
結果
AC  
実行時間 889 ms / 3,000 ms
コード長 471 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 7,044 KB
実行使用メモリ 6,460 KB
最終ジャッジ日時 2023-08-22 08:50:02
合計ジャッジ時間 12,143 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 410 ms
6,276 KB
testcase_01 AC 400 ms
6,432 KB
testcase_02 AC 47 ms
6,208 KB
testcase_03 AC 45 ms
6,376 KB
testcase_04 AC 813 ms
6,380 KB
testcase_05 AC 812 ms
6,316 KB
testcase_06 AC 813 ms
6,416 KB
testcase_07 AC 814 ms
6,432 KB
testcase_08 AC 887 ms
6,256 KB
testcase_09 AC 889 ms
6,460 KB
testcase_10 AC 886 ms
6,248 KB
testcase_11 AC 814 ms
6,248 KB
testcase_12 AC 814 ms
6,264 KB
testcase_13 AC 16 ms
6,028 KB
testcase_14 AC 15 ms
6,088 KB
testcase_15 AC 37 ms
6,232 KB
testcase_16 AC 38 ms
6,164 KB
testcase_17 AC 11 ms
6,116 KB
testcase_18 AC 270 ms
6,300 KB
testcase_19 AC 12 ms
6,012 KB
testcase_20 AC 559 ms
6,392 KB
testcase_21 AC 11 ms
6,136 KB
testcase_22 AC 813 ms
6,456 KB
testcase_23 AC 11 ms
6,148 KB
testcase_24 AC 11 ms
6,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n = input()
d = 1
x = 0
v = []
for i in xrange(n):
    X, Y = map(int, raw_input().split())
    g, a, b = extgcd(d, Y)
    x, d = (Y*b*x + d*a*X)/g, d*(Y / g)
    x = (x + d) % d
    v.append((X, Y))

for X, Y in v:
    if x % Y != X:
        print -1
        exit(0)
if x == 0:
    print d % (10**9+7)
else:
    print x % (10**9+7)
0