結果

問題 No.2767 Add to Divide
ユーザー p-adicp-adic
提出日時 2024-05-08 14:36:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-05-08 14:36:55
合計ジャッジ時間 6,021 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
11,520 KB
testcase_01 AC 81 ms
11,392 KB
testcase_02 AC 177 ms
11,520 KB
testcase_03 AC 315 ms
11,520 KB
testcase_04 AC 294 ms
11,520 KB
testcase_05 AC 345 ms
11,520 KB
testcase_06 AC 312 ms
11,520 KB
testcase_07 AC 309 ms
11,520 KB
testcase_08 AC 310 ms
11,392 KB
testcase_09 AC 317 ms
11,392 KB
testcase_10 AC 325 ms
11,520 KB
testcase_11 AC 337 ms
11,392 KB
testcase_12 AC 311 ms
11,520 KB
testcase_13 AC 312 ms
11,392 KB
testcase_14 AC 309 ms
11,392 KB
testcase_15 AC 310 ms
11,520 KB
testcase_16 AC 315 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

I,R,O=input,range,print
L=9**5
P=[]
C=[0]*L
for i in R(2,L):
	if C[i]<1:
		P+=[i]
		j=i*i
		while j<L:C[j],j=1,j+i
for t in R(int(I())):
	A,B=map(int,I().split())
	t=e=B-A
	if e:
		if A<2:t=1
		D=[1]
		for p in P:
			c=0
			while e%p<1:e//=p;c+=1;
			r=len(D)
			for i in R(c):
				for m in[n*p for n in D[-r:]]:
					D+=[m]
					if A<=m<t:t=m
		r=len(D)
		if e>1:
			for m in[n*e for n in D[-r:]]:
				D+=[m]
				if A<=m<t:t=m
	print([0,max(t-A,-1)][e>0])
0