結果

問題 No.2420 Simple Problem
ユーザー iseeisee
提出日時 2023-08-12 14:13:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,294 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 99,700 KB
最終ジャッジ日時 2024-04-30 05:22:16
合計ジャッジ時間 7,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
61,844 KB
testcase_01 AC 1,710 ms
85,828 KB
testcase_02 AC 82 ms
75,828 KB
testcase_03 AC 685 ms
79,860 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()

def naive(A, B):
    ng = -1
    ok = (A+B)*2
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        if mid*mid-A-B > 0 and 4*A*B < (mid*mid-A-B)**2:  # ここ頑張る
            ok = mid
        else:
            ng = mid
    return ok

def isqrt(n):
    # n <= X^2 なる最小の X を求める
    ng = 0
    ok = n*2
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        if n <= mid*mid : # ここ頑張る
            ok = mid
        else:
            ng = mid
    return ok

def solve(A, B):
    # vA + vB < X
    # A + 2vAB + B < X2
    # 2vAB < X2 - A - B =: C
    # 4AB < C2
    iseq = True
    C = isqrt(4*A*B)
    iseq &= 4*A*B == C * C
    X = isqrt(C+A+B)
    iseq &= C+A+B == X * X
    return X+iseq

def main():
    # 入力
    N = int(input())
    for _ in range(N):
        A, B = map(int, input().split())
        # 計算・出力
        ans = naive(A, B)
        print(ans)

if __name__ == "__main__":
    main()
    from random import randint
    # for _ in range(10000):
    #     A = randint(1, 10**9)
    #     B = randint(1, 10**9)
    #     ans1 = naive(A, B)
    #     ans2 = solve(A, B)
    #     if ans1 != ans2:
    #         print(A, B)
    #         print(ans1, ans2)
    #         break
0