結果

問題 No.187 中華風 (Hard)
ユーザー 👑 timitimi
提出日時 2020-12-21 11:53:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 665 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 12,068 KB
実行使用メモリ 10,596 KB
最終ジャッジ日時 2023-10-21 11:35:08
合計ジャッジ時間 2,663 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,480 KB
testcase_01 AC 34 ms
10,480 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 31 ms
10,320 KB
testcase_18 AC 33 ms
10,460 KB
testcase_19 AC 31 ms
10,320 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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=int(input())
P=[]
for i in range(N):
  x,y=map(int, input().split())
  P.append((x,y))
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])
  #print(T[0],T[1],P[i][0],P[i][1])
  #print(T2,'modと最小公倍数')
  if T2[0]==-1:
    print(-1)
    exit()
  T=[int(T2[0]),int(T2[1])]

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

print(T[0]%(10**9+7))
0