結果

問題 No.2420 Simple Problem
ユーザー Seed57_cash
提出日時 2023-06-21 09:41:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 624 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2024-06-28 19:35:28
合計ジャッジ時間 20,362 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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