結果
問題 | No.2767 Add to Divide |
ユーザー |
![]() |
提出日時 | 2024-05-31 22:11:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 214 ms / 2,000 ms |
コード長 | 1,454 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 89,472 KB |
最終ジャッジ日時 | 2024-12-20 23:43:29 |
合計ジャッジ時間 | 4,809 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
from heapq import heappush, heappop, heapifyfrom collections import defaultdict, deque,Counterfrom math import ceil, floor, sqrt, factorial,gcd,cos,sin,pifrom itertools import permutations, combinations,productfrom bisect import bisect_left, bisect_rightfrom copy import deepcopyfrom fractions import Fractionfrom random import randintimport sysfrom functools import cache,lru_cache #@lru_cache(maxsize=None)from time import time#from sortedcontainers import SortedList # type: ignore#sys.setrecursionlimit(10**6)vector1 = [[0, -1], [1, 0], [0, 1], [-1, 0]]vector2 = [[0, 1], [1, 0], [-1, 0], [0, -1],[1,-1], [-1, 1], [1, 1], [-1, -1]]alphabet = "abcdefghijklmnopqrstuvwxyz"def make_divisors(n):lower_divisors, upper_divisors = [], []i = 1while i * i <= n:if n % i == 0:lower_divisors.append(i)if i != n // i:upper_divisors.append(n//i)i += 1return lower_divisors + upper_divisors[::-1]def main():for _ in range(int(input())):a,b = map(int,input().split())if b%a == 0:print(0)continuedivisors = make_divisors(b-a)f = Truefor divisor in divisors:if divisor > a:print(divisor-a)f = Falsebreakif f:print(-1)if __name__ == '__main__':main()