結果

問題 No.2767 Add to Divide
コンテスト
ユーザー ra5anchor
提出日時 2024-06-04 05:05:23
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 524 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 62 ms
コンパイル使用メモリ 81,328 KB
実行使用メモリ 63,236 KB
最終ジャッジ日時 2026-10-06 12:15:21
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

def f(dv, a):
    for x in dv:
        if a <= x:
            return x
    return -1


T = int(input())
for t in range(T):
    a, b = map(int, input().split())
    dv = divisors(b-a)
    res = f(dv, a)
    if res == -1:
        print(-1)
    else:
        print(res - a)
0