結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
78,908 KB
testcase_01 AC 87 ms
79,216 KB
testcase_02 AC 221 ms
79,928 KB
testcase_03 WA -
testcase_04 AC 425 ms
81,040 KB
testcase_05 AC 416 ms
80,184 KB
testcase_06 WA -
testcase_07 AC 429 ms
82,096 KB
testcase_08 AC 444 ms
80,088 KB
testcase_09 AC 443 ms
79,960 KB
testcase_10 AC 448 ms
79,944 KB
testcase_11 AC 417 ms
79,980 KB
testcase_12 WA -
testcase_13 AC 94 ms
79,156 KB
testcase_14 AC 93 ms
79,160 KB
testcase_15 AC 132 ms
80,176 KB
testcase_16 AC 138 ms
80,180 KB
testcase_17 AC 74 ms
76,164 KB
testcase_18 AC 88 ms
79,096 KB
testcase_19 AC 74 ms
76,440 KB
testcase_20 WA -
testcase_21 AC 75 ms
76,528 KB
testcase_22 WA -
testcase_23 AC 75 ms
76,436 KB
testcase_24 AC 74 ms
76,304 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%=mo1
	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