結果

問題 No.2767 Add to Divide
ユーザー i_taku
提出日時 2024-06-01 20:22:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,004 KB
実行使用メモリ 67,040 KB
最終ジャッジ日時 2024-12-22 09:20:11
合計ジャッジ時間 2,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i**2 <= 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]


T = int(input())
ans = []
for _ in range(T):
    A, B = map(int, input().split())
    if A == B:
        ans.append(0)
        continue
    divs = make_divisors(B - A)
    X = []
    for div in divs:
        x = div - A
        if 0 <= x:
            X.append(x)
    ans.append(min(X) if X else -1)
print(*ans, sep='\n')
0