結果

問題 No.187 中華風 (Hard)
ユーザー fmhr
提出日時 2015-04-20 07:25:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 689 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-04 16:58:28
合計ジャッジ時間 8,803 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python

import sys
from functools import reduce

def egcd(x, y):
	if y == 0:
		return (x, 1, 0)
	(d, a, b) = egcd(y, x % y)
	return (d, b, a - (x // y) * b)

def crt(p, m, q, n):
	a, d, r = egcd(p, q)
	if (n - m) % a != 0:
		return (-1, -1)
	mod = p * (q // a)
	a = (d * ((n - m) // a) * p + m) % mod
	return (a, mod)

def chinese_remainder(items):
	xx = 0
	yy = 1
	for x, y in items:
		xx, yy = crt(y, x, yy, xx)
		if xx == -1:
			print(-1)
			sys.exit(0)
	if xx == 0: xx == yy
	return xx
	
#print(chinese_remainder([(10, 20), (10, 30), (10, 40)]))
n = int(input())
x = [0] * n
for i in range(n):
	x[i] = tuple(map(int, input().split()))
print(chinese_remainder(x) % (10**9+7))
0