結果

問題 No.187 中華風 (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2015-04-19 23:59:43
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 451 ms / 3,000 ms
コード長 572 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 77,636 KB
実行使用メモリ 82,240 KB
最終ジャッジ日時 2023-09-18 02:10:13
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
78,968 KB
testcase_01 AC 89 ms
79,080 KB
testcase_02 AC 224 ms
80,096 KB
testcase_03 AC 235 ms
80,456 KB
testcase_04 AC 430 ms
81,116 KB
testcase_05 AC 422 ms
80,020 KB
testcase_06 AC 422 ms
79,996 KB
testcase_07 AC 435 ms
82,240 KB
testcase_08 AC 447 ms
80,080 KB
testcase_09 AC 445 ms
80,152 KB
testcase_10 AC 451 ms
79,952 KB
testcase_11 AC 420 ms
80,140 KB
testcase_12 AC 420 ms
80,184 KB
testcase_13 AC 95 ms
79,128 KB
testcase_14 AC 92 ms
79,296 KB
testcase_15 AC 132 ms
79,900 KB
testcase_16 AC 141 ms
79,972 KB
testcase_17 AC 74 ms
76,540 KB
testcase_18 AC 89 ms
79,100 KB
testcase_19 AC 76 ms
76,456 KB
testcase_20 AC 322 ms
79,912 KB
testcase_21 AC 75 ms
76,116 KB
testcase_22 AC 427 ms
80,048 KB
testcase_23 AC 74 ms
76,552 KB
testcase_24 AC 75 ms
76,664 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)
	v=a1+((a2-a1)%lcm)*x%lcm*(mo1/g)
	return (((v%lcm)+lcm) % 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