結果

問題 No.2420 Simple Problem
ユーザー Seed57_cash
提出日時 2023-06-21 09:39:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 907 bytes
コンパイル時間 1,239 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2024-06-28 19:33:14
合計ジャッジ時間 22,141 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 26 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

# 小数の誤差がありそうなので整数に帰着させる

# 与えられたrが条件を満たすかの正確な判定
# r >= math.sqrt(a) + math.sqrt(b)
# r ** 2 >= a + b + 2 * math.sqrt(a * b) and r >= 0
# r ** 2 - a - b >= 2 * math.sqrt(a * b) and r >= 0
# (r ** 2 - a - b) ** 2 >= 4 * a * b and r >= 0 and r ** 2 - a - b >= 0

import math


def check(a, b, r):
	if (r ** 2 - a - b) ** 2 >= 4 * a * b and (r ** 2 - a - b) >= 0 and r >= 0:
		return True
	else:
		return False
		

def solve(a, b):
	# 余裕みて少し大きめな数を取って、2減らしたものまでを試す(二分探索でも全然OK)
	res = math.ceil(math.sqrt(a)) + math.ceil(math.sqrt(b))
	if check(a, b, res - 2) == True:
		return res - 2
	elif check(a, b, res - 1) == True:
		return res - 1
	else:
		return res
	

# main
n = int(input())
for _ in range(n):
	a, b = map(int, input().split())
	print(solve(a, b))
0