結果

問題 No.2420 Simple Problem
ユーザー Kyoro ID
提出日時 2023-08-13 09:15:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 985 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 95,948 KB
最終ジャッジ日時 2024-11-21 02:54:51
合計ジャッジ時間 18,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import logging
import math
input = sys.stdin.readline
logger = logging.getLogger(__name__)


def read():
    N = int(input().strip())
    AB = []
    for i in range(N):
        a, b = map(int, input().strip().split())
        AB.append((a, b))
    return N, AB


def judge(x, a, b):
    left = a * b * 4
    right = (x * x - a - b) * (x * x - a - b)
    return left < right


def solve(N, AB):
    for a, b in AB:
        ok = 10**11
        ng = 2
        while abs(ok - ng) > 1:
            x = (ok + ng) // 2
            if judge(x, a, b):
                ok = x
            else:
                ng = x
        ans = 0
        for x in (ok-1, ok, ok+1):
            if judge(x, a, b):
                ans = x
                break
        if ans == 0:
            raise RuntimeError
        else:
            print(ans)
        


if __name__ == "__main__":
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
0