結果

問題 No.2767 Add to Divide
ユーザー shobonvip
提出日時 2024-05-31 22:40:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 62,444 KB
最終ジャッジ日時 2024-12-21 00:27:26
合計ジャッジ時間 2,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

def solve():
	a, b = map(int,input().split())
	if b % a == 0:
		print(0)
		return
	d = makediv(b - a)
	x = 10 ** 18
	for i in d:
		if i - a < 0: continue
		x = min(x, i - a)
	if x == 10 ** 18:
		print(-1)
	else:
		print(x)


T = int(input())
for _ in range(T):
	solve()
0