結果

問題 No.2767 Add to Divide
ユーザー ああいいああいい
提出日時 2024-06-01 16:41:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 329 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 63,360 KB
最終ジャッジ日時 2024-12-22 03:03:50
合計ジャッジ時間 3,844 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

for _ in range(T):
	a,b = map(int,input().split())
	c = b - a
	if c == 0:
		print(0)
		continue
	if c < a:
		print(-1)
	else:
		s = set()
		for i in range(1,10 ** 5):
			if c % i == 0:
				s.add(i)
				s.add(c // i)
		s.add(c)
		ans = 10 ** 20
		for k in s:
			if k >= a and k - a < ans:ans = k - a
		print(ans)
0