結果

問題 No.187 中華風 (Hard)
ユーザー snukesnuke
提出日時 2015-04-20 16:10:29
言語 Python2
(2.7.18)
結果
AC  
実行時間 877 ms / 3,000 ms
コード長 350 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 6,212 KB
最終ジャッジ日時 2023-09-18 01:13:55
合計ジャッジ時間 10,276 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,836 KB
testcase_01 AC 11 ms
5,944 KB
testcase_02 AC 43 ms
6,108 KB
testcase_03 AC 43 ms
6,124 KB
testcase_04 AC 801 ms
6,120 KB
testcase_05 AC 798 ms
6,100 KB
testcase_06 AC 796 ms
6,076 KB
testcase_07 AC 799 ms
6,212 KB
testcase_08 AC 877 ms
6,120 KB
testcase_09 AC 873 ms
6,176 KB
testcase_10 AC 873 ms
6,072 KB
testcase_11 AC 806 ms
6,172 KB
testcase_12 AC 800 ms
6,068 KB
testcase_13 AC 15 ms
5,948 KB
testcase_14 AC 15 ms
5,808 KB
testcase_15 AC 38 ms
6,076 KB
testcase_16 AC 38 ms
5,940 KB
testcase_17 AC 11 ms
5,864 KB
testcase_18 AC 11 ms
5,960 KB
testcase_19 AC 11 ms
5,812 KB
testcase_20 AC 548 ms
6,112 KB
testcase_21 AC 11 ms
5,952 KB
testcase_22 AC 803 ms
6,072 KB
testcase_23 AC 11 ms
5,812 KB
testcase_24 AC 11 ms
5,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(raw_input())

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

def fail():
  print -1
  exit(0)

a = 0
b = 1
for i in xrange(n):
  na,nb = map(int,raw_input().split())
  g,x,y = extgcd(b,nb)
  if a%g != na%g: fail()
  l = b/g*nb
  a,b = ((a+(na-a)/g*x*b)%l,l)

if a == 0: a = b
print a%1000000007
0