結果

問題 No.2767 Add to Divide
ユーザー naesiranaesira
提出日時 2024-05-31 21:38:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 61,784 KB
最終ジャッジ日時 2024-05-31 21:38:44
合計ジャッジ時間 2,189 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
57,744 KB
testcase_01 AC 44 ms
57,944 KB
testcase_02 AC 39 ms
53,664 KB
testcase_03 AC 84 ms
61,784 KB
testcase_04 AC 39 ms
53,904 KB
testcase_05 AC 68 ms
60,340 KB
testcase_06 AC 66 ms
60,140 KB
testcase_07 AC 70 ms
61,408 KB
testcase_08 AC 79 ms
60,496 KB
testcase_09 AC 74 ms
60,820 KB
testcase_10 AC 75 ms
60,608 KB
testcase_11 AC 75 ms
59,824 KB
testcase_12 AC 76 ms
59,888 KB
testcase_13 AC 72 ms
60,264 KB
testcase_14 AC 74 ms
61,228 KB
testcase_15 AC 72 ms
60,636 KB
testcase_16 AC 71 ms
59,760 KB
権限があれば一括ダウンロードができます

ソースコード

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