結果

問題 No.2420 Simple Problem
ユーザー rlangevin
提出日時 2023-09-03 15:24:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 85,072 KB
最終ジャッジ日時 2024-06-12 21:08:18
合計ジャッジ時間 24,056 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import sqrt, ceil

def isqrt(n):
    yes = 0
    no = 10 ** 18
    while no - yes != 1:
        mid = (yes + no)//2
        if mid * mid <= n:
            yes = mid
        else:
            no = mid
    return yes * yes == n, yes
    

N = int(input())
for _ in range(N):
    A, B = map(int, input().split())
    fa, na = isqrt(A)
    fb, nb = isqrt(B)
    if fa and fb:
        print(na + nb + 1)
    else:
        print(ceil(sqrt(A) + sqrt(B)))
0