結果

問題 No.2767 Add to Divide
ユーザー anonymouslyanonymously
提出日時 2024-05-31 22:20:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-31 22:20:30
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,880 KB
testcase_01 AC 56 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 400 ms
10,880 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 AC 267 ms
10,752 KB
testcase_06 AC 265 ms
10,752 KB
testcase_07 AC 269 ms
10,752 KB
testcase_08 AC 341 ms
10,752 KB
testcase_09 AC 330 ms
10,752 KB
testcase_10 AC 340 ms
10,880 KB
testcase_11 AC 338 ms
10,880 KB
testcase_12 AC 322 ms
10,752 KB
testcase_13 AC 323 ms
10,752 KB
testcase_14 AC 322 ms
10,752 KB
testcase_15 AC 314 ms
10,752 KB
testcase_16 AC 324 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisors(n, a):
    result = []
    i = 1
    while i*i <= n:
        if n % i == 0:
            if i >= a:
                result.append(i)
            if i*i < n and n >= a*i:
                result.append(n//i)
        i += 1
    return sorted(result)


def solve(a, b):
    if a == b:
        return 0
    d = divisors(b-a, a)
    if d:
        return d[0]-a
    else:
        return -1


for t in range(int(input())):
    print(solve(*[int(a) for a in input().split()]))
0