結果

問題 No.187 中華風 (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2015-04-20 00:14:22
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 440 ms / 3,000 ms
コード長 557 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 77,784 KB
実行使用メモリ 81,036 KB
最終ジャッジ日時 2023-09-18 02:16:34
合計ジャッジ時間 7,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
79,120 KB
testcase_01 AC 89 ms
79,104 KB
testcase_02 AC 220 ms
80,072 KB
testcase_03 AC 229 ms
80,400 KB
testcase_04 AC 417 ms
81,036 KB
testcase_05 AC 412 ms
80,280 KB
testcase_06 AC 414 ms
79,800 KB
testcase_07 AC 422 ms
81,020 KB
testcase_08 AC 438 ms
80,204 KB
testcase_09 AC 440 ms
80,212 KB
testcase_10 AC 438 ms
80,096 KB
testcase_11 AC 417 ms
80,260 KB
testcase_12 AC 414 ms
80,108 KB
testcase_13 AC 93 ms
79,224 KB
testcase_14 AC 93 ms
79,296 KB
testcase_15 AC 130 ms
80,012 KB
testcase_16 AC 137 ms
79,896 KB
testcase_17 AC 75 ms
76,256 KB
testcase_18 AC 87 ms
79,084 KB
testcase_19 AC 74 ms
76,452 KB
testcase_20 AC 316 ms
79,912 KB
testcase_21 AC 74 ms
76,452 KB
testcase_22 AC 419 ms
79,956 KB
testcase_23 AC 75 ms
76,460 KB
testcase_24 AC 75 ms
76,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def ext_gcd(p,q):
	if q==0:
		return (p,1,0)
	g,y,x = ext_gcd(q,p%q);
	y -= p/q*x
	return (g,x,y)

def cmt(a1,mo1,a2,mo2):
	g,x,y=ext_gcd(mo1,mo2)
	a1%=mo1
	a2%=mo2
	if a1%g != a2%g:
		return (-1,0)
	lcm=mo1*(mo2/g)
	return ((a1+((a2-a1)%lcm)*x%lcm*(mo1/g)) % lcm,lcm)

N=input()
P=[]
for i in range(N):
	P.append(map(int,raw_input().strip().split(" ")))

T=[P[0][0],P[0][1]]
for i in range(1,N):
	T2=cmt(T[0],T[1],P[i][0],P[i][1])
	if T2[0]<0:
		print -1
		sys.exit()
	T=[T2[0],T2[1]]

if T[0]==0:
	T[0]=T[1]

print T[0]%1000000007
0