結果

問題 No.2767 Add to Divide
ユーザー hato336hato336
提出日時 2024-05-31 21:50:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 985 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,624 KB
実行使用メモリ 90,040 KB
最終ジャッジ日時 2024-05-31 21:50:50
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#n = int(input())
#alist = list(map(int,input().split()))
#alist = []
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= 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]
#s = input()
t = int(input())
for i in range(t):
    a,b = map(int,input().split())
    if b % a == 0:
        print(0)
        continue
    c = math.gcd(a,b)
    a //= c
    b //= c
    g = b-a
    for j in make_divisors(g):
        if j == 1:
            continue
        if a % j == b % j:
            if j-a >= 0:
                print(j-a)
                break
            
    else:
        print(-1)
        continue
    print(-1)
0