結果

問題 No.2767 Add to Divide
ユーザー vwxyzvwxyz
提出日時 2024-08-09 04:38:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-08-09 04:38:39
合計ジャッジ時間 5,809 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 52 ms
10,752 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 408 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 268 ms
10,880 KB
testcase_06 AC 283 ms
10,752 KB
testcase_07 AC 266 ms
10,752 KB
testcase_08 AC 353 ms
10,752 KB
testcase_09 AC 328 ms
10,752 KB
testcase_10 AC 356 ms
10,752 KB
testcase_11 AC 345 ms
10,752 KB
testcase_12 AC 319 ms
10,880 KB
testcase_13 AC 340 ms
10,880 KB
testcase_14 AC 318 ms
10,752 KB
testcase_15 AC 311 ms
10,880 KB
testcase_16 AC 314 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Divisors(N):
    divisors=[]
    for i in range(1,N+1):
        if i**2>=N:
            break
        elif N%i==0:
            divisors.append(i)
    if i**2==N:
        divisors+=[i]+[N//i for i in divisors[::-1]]
    else:
        divisors+=[N//i for i in divisors[::-1]]
    return divisors

T=int(input())
for t in range(T):
    A,B=map(int,input().split())
    if A==B:
        ans=0
    else:
        inf=1<<60
        ans=inf
        for d in Divisors(B-A):
            if d>=A:
                ans=min(ans,d-A)
        if ans==inf:
            ans=-1
    print(ans)
0