結果

問題 No.2767 Add to Divide
ユーザー ra5anchorra5anchor
提出日時 2024-06-04 05:08:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 60,800 KB
最終ジャッジ日時 2024-06-04 05:08:25
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,216 KB
testcase_01 AC 45 ms
57,472 KB
testcase_02 AC 41 ms
52,224 KB
testcase_03 AC 86 ms
60,800 KB
testcase_04 AC 41 ms
52,608 KB
testcase_05 AC 72 ms
59,520 KB
testcase_06 AC 72 ms
58,880 KB
testcase_07 AC 78 ms
59,264 KB
testcase_08 AC 78 ms
59,264 KB
testcase_09 AC 78 ms
59,392 KB
testcase_10 AC 78 ms
59,520 KB
testcase_11 AC 79 ms
58,624 KB
testcase_12 AC 78 ms
59,520 KB
testcase_13 AC 78 ms
58,880 KB
testcase_14 AC 78 ms
59,392 KB
testcase_15 AC 74 ms
58,752 KB
testcase_16 AC 76 ms
58,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ANS = []
T = int(input())
for t in range(T):
    a, b = map(int, input().split())
    dv = divisors(b-a)
    res = f(dv, a)
    if a == b:
        ANS.append(0)
    elif res == -1:
        ANS.append(-1)
        # print(-1)
    else:
        ANS.append(res - a)
        # print(res - a)
for ans in ANS:
    print(ans)
# print(*ANS)
0