結果

問題 No.2767 Add to Divide
ユーザー p-adicp-adic
提出日時 2024-05-08 14:26:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 419 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 69,376 KB
最終ジャッジ日時 2024-05-08 14:31:53
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
63,232 KB
testcase_01 AC 63 ms
64,128 KB
testcase_02 AC 65 ms
64,640 KB
testcase_03 AC 93 ms
69,376 KB
testcase_04 AC 72 ms
65,444 KB
testcase_05 AC 75 ms
66,784 KB
testcase_06 AC 73 ms
65,300 KB
testcase_07 AC 103 ms
66,896 KB
testcase_08 AC 71 ms
66,064 KB
testcase_09 AC 70 ms
65,192 KB
testcase_10 AC 72 ms
65,756 KB
testcase_11 AC 72 ms
66,772 KB
testcase_12 AC 73 ms
67,656 KB
testcase_13 AC 72 ms
65,936 KB
testcase_14 AC 73 ms
66,860 KB
testcase_15 AC 73 ms
66,340 KB
testcase_16 AC 74 ms
66,164 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