結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
11,392 KB
testcase_01 AC 76 ms
11,520 KB
testcase_02 AC 163 ms
11,392 KB
testcase_03 AC 293 ms
11,520 KB
testcase_04 AC 290 ms
11,520 KB
testcase_05 AC 325 ms
11,392 KB
testcase_06 AC 297 ms
11,520 KB
testcase_07 AC 296 ms
11,520 KB
testcase_08 AC 314 ms
11,392 KB
testcase_09 AC 296 ms
11,520 KB
testcase_10 AC 311 ms
11,520 KB
testcase_11 AC 302 ms
11,392 KB
testcase_12 AC 300 ms
11,392 KB
testcase_13 AC 290 ms
11,520 KB
testcase_14 AC 311 ms
11,520 KB
testcase_15 AC 312 ms
11,392 KB
testcase_16 AC 289 ms
11,520 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:
		D=[1]
		for p in P:
			c=0
			while e%p<1:e//=p;c+=1;
			r=len(D)
			for i in R(c):D+=[n*p for n in D[-r:]]
		r=len(D)
		if e>1:D+=[n*e for n in D[-r:]];r*=2
		D.sort()
		r-=1
		while r and D[r-1]>=A:r-=1
	print(max(D[r]-A,-1)if e else 0)
0