結果

問題 No.186 中華風 (Easy)
ユーザー fmhrfmhr
提出日時 2015-04-20 07:28:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-09-18 00:04:21
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,736 KB
testcase_01 AC 20 ms
8,736 KB
testcase_02 AC 21 ms
8,736 KB
testcase_03 AC 21 ms
8,624 KB
testcase_04 AC 20 ms
8,788 KB
testcase_05 AC 21 ms
8,600 KB
testcase_06 AC 20 ms
8,592 KB
testcase_07 AC 20 ms
8,724 KB
testcase_08 AC 21 ms
8,632 KB
testcase_09 AC 21 ms
8,628 KB
testcase_10 AC 22 ms
8,664 KB
testcase_11 AC 21 ms
8,724 KB
testcase_12 AC 21 ms
8,752 KB
testcase_13 AC 21 ms
8,760 KB
testcase_14 AC 21 ms
8,624 KB
testcase_15 AC 20 ms
8,684 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 21 ms
8,732 KB
testcase_19 AC 21 ms
8,752 KB
testcase_20 AC 21 ms
8,624 KB
testcase_21 AC 21 ms
8,616 KB
testcase_22 AC 20 ms
8,624 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 3
x = [0] * n
for i in range(n):
	x[i] = tuple(map(int, input().split()))
print(chinese_remainder(x))
0