結果

問題 No.2767 Add to Divide
ユーザー june19312june19312
提出日時 2024-05-31 22:57:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 490 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 81,964 KB
実行使用メモリ 122,376 KB
最終ジャッジ日時 2024-12-21 01:06:33
合計ジャッジ時間 23,304 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
#4394 993298361
for j in range(T):
    a,b = map(int,input().split())
    if b%a == 0:
        print(0)
        continue
    elif b//a < 2:
        print(-1)
        continue

    for k in range(b//a,1,-1):
        ok,ng = 0,10**10

        while abs(ok-ng) > 1:
            mid = abs((ok+ng)//2)
            if (b+mid)//(a+mid) < k:
                ng = mid
            else:
                ok = mid

        if (b+ok)%(a+ok) == 0:
            print(ok)
            break
0