結果

問題 No.2767 Add to Divide
ユーザー なえしら
提出日時 2024-05-31 21:38:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 62,380 KB
最終ジャッジ日時 2024-12-20 22:48:41
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import isqrt
def divisors(n):
  r = isqrt(n-1)+1
  small, large = [], []
  for i in range(1, r):
    if n%i == 0:
      small.append(i)
      large.append(n//i)
  if r**2 == n: small.append(r)
  return small + large[::-1]

T = int(input())
for _ in range(T):
  A, B = map(int, input().split())
  if A == B:
  	print(0)
  	continue
  D = divisors(B - A)
  for d in D:
    if d >= A:
      print(d - A)
      break
  else: print(-1)
0