結果

問題 No.2420 Simple Problem
ユーザー Seed57_cashSeed57_cash
提出日時 2023-06-21 09:39:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 907 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 79,008 KB
最終ジャッジ日時 2023-09-11 05:10:18
合計ジャッジ時間 23,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 365 ms
78,620 KB
testcase_02 AC 106 ms
76,100 KB
testcase_03 AC 215 ms
78,696 KB
testcase_04 AC 576 ms
78,772 KB
testcase_05 AC 416 ms
78,628 KB
testcase_06 AC 681 ms
78,704 KB
testcase_07 AC 681 ms
78,728 KB
testcase_08 AC 687 ms
78,756 KB
testcase_09 AC 682 ms
78,644 KB
testcase_10 AC 693 ms
78,616 KB
testcase_11 AC 688 ms
79,008 KB
testcase_12 AC 691 ms
78,580 KB
testcase_13 AC 685 ms
78,816 KB
testcase_14 AC 674 ms
78,716 KB
testcase_15 AC 674 ms
78,648 KB
testcase_16 AC 683 ms
78,620 KB
testcase_17 AC 679 ms
78,592 KB
testcase_18 AC 679 ms
78,720 KB
testcase_19 AC 690 ms
78,608 KB
testcase_20 AC 677 ms
78,604 KB
testcase_21 AC 688 ms
78,460 KB
testcase_22 AC 680 ms
78,664 KB
testcase_23 AC 688 ms
78,792 KB
testcase_24 AC 682 ms
78,692 KB
testcase_25 AC 675 ms
78,468 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 355 ms
78,576 KB
権限があれば一括ダウンロードができます

ソースコード

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