結果

問題 No.2767 Add to Divide
ユーザー p-adicp-adic
提出日時 2024-05-08 14:35:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 73,728 KB
最終ジャッジ日時 2024-05-08 14:36:13
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
63,232 KB
testcase_01 AC 60 ms
64,384 KB
testcase_02 AC 65 ms
65,408 KB
testcase_03 AC 82 ms
73,728 KB
testcase_04 AC 67 ms
64,384 KB
testcase_05 AC 78 ms
65,920 KB
testcase_06 AC 69 ms
64,768 KB
testcase_07 AC 72 ms
66,432 KB
testcase_08 AC 72 ms
66,432 KB
testcase_09 AC 69 ms
65,536 KB
testcase_10 AC 71 ms
66,816 KB
testcase_11 AC 71 ms
66,432 KB
testcase_12 AC 77 ms
67,840 KB
testcase_13 AC 74 ms
66,816 KB
testcase_14 AC 74 ms
66,688 KB
testcase_15 AC 77 ms
67,200 KB
testcase_16 AC 73 ms
66,048 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