結果

問題 No.2767 Add to Divide
ユーザー hato336
提出日時 2024-05-31 21:50:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 89,984 KB
最終ジャッジ日時 2024-12-20 23:10:52
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 16
権限があれば一括ダウンロードができます

ソースコード

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)
    print(-1)
0