結果

問題 No.187 中華風 (Hard)
ユーザー uwiuwi
提出日時 2015-04-19 23:35:59
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 830 ms / 3,000 ms
コード長 543 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 8,480 KB
最終ジャッジ日時 2023-09-18 01:29:02
合計ジャッジ時間 10,078 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,168 KB
testcase_01 AC 17 ms
8,196 KB
testcase_02 AC 55 ms
8,368 KB
testcase_03 AC 55 ms
8,384 KB
testcase_04 AC 759 ms
8,428 KB
testcase_05 AC 755 ms
8,480 KB
testcase_06 AC 760 ms
8,344 KB
testcase_07 AC 761 ms
8,456 KB
testcase_08 AC 827 ms
8,380 KB
testcase_09 AC 829 ms
8,348 KB
testcase_10 AC 830 ms
8,336 KB
testcase_11 AC 760 ms
8,404 KB
testcase_12 AC 759 ms
8,464 KB
testcase_13 AC 20 ms
8,240 KB
testcase_14 AC 20 ms
8,260 KB
testcase_15 AC 48 ms
8,188 KB
testcase_16 AC 49 ms
8,200 KB
testcase_17 AC 16 ms
7,924 KB
testcase_18 AC 17 ms
8,164 KB
testcase_19 AC 16 ms
7,772 KB
testcase_20 AC 523 ms
8,328 KB
testcase_21 AC 16 ms
7,780 KB
testcase_22 AC 755 ms
8,380 KB
testcase_23 AC 17 ms
7,756 KB
testcase_24 AC 16 ms
7,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def exgcd(a, b):
	p = 1; q = 0; r = 0; s = 1;
	while b > 0:
		c = a//b
		d = a; a = b; b = d % b;
		d = p; p = q; q = d - c * q;
		d = r; r = s; s = d - c * s;
	return (a, p, r)

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

import sys
n = int(input())
xx = 0; yy = 1;
for _ in range(n):
	x,y = map(int,input().split())
	xx,yy = crt(y, x, yy, xx)
	if xx == -1:
		print(-1)
		sys.exit(0)
if xx == 0:
	xx = yy
print(xx % 1000000007)
0