結果
| 問題 | No.2767 Add to Divide |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-31 21:47:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 2,000 ms |
| コード長 | 822 bytes |
| コンパイル時間 | 415 ms |
| コンパイル使用メモリ | 82,076 KB |
| 実行使用メモリ | 67,752 KB |
| 最終ジャッジ日時 | 2024-12-20 23:04:05 |
| 合計ジャッジ時間 | 2,539 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 |
ソースコード
S = input
R = range
P = print
def I(): return int(S())
def M(): return map(int, S().split())
def L(): return list(M())
def O(): return list(map(int, open(0).read().split()))
def yn(b): print("Yes" if b else "No")
biga = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
smaa = "abcdefghijklmnopqrstuvwxyz"
def make_divisors(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]
for _ in R(I()):
a, b = M()
if a == b:
print(0)
continue
c = 10 ** 15
# b - a の約数を全探索
for i in make_divisors(b - a):
if i >= a and (b + i - a) % (a + i - a) == 0:
c = min(c, i - a)
print(c if c < 10 ** 15 else -1)