結果
問題 |
No.2767 Add to Divide
|
ユーザー |
|
提出日時 | 2024-05-31 21:50:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 985 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 91,716 KB |
最終ジャッジ日時 | 2024-12-20 23:11:23 |
合計ジャッジ時間 | 4,202 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 16 |
ソースコード
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)