結果

問題 No.2420 Simple Problem
ユーザー Seed57_cashSeed57_cash
提出日時 2023-06-21 09:41:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 707 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 1,442 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 78,796 KB
最終ジャッジ日時 2023-09-11 05:12:58
合計ジャッジ時間 24,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,384 KB
testcase_01 AC 399 ms
78,608 KB
testcase_02 AC 107 ms
76,360 KB
testcase_03 AC 219 ms
78,456 KB
testcase_04 AC 579 ms
78,504 KB
testcase_05 AC 415 ms
78,452 KB
testcase_06 AC 677 ms
78,228 KB
testcase_07 AC 679 ms
78,500 KB
testcase_08 AC 680 ms
78,252 KB
testcase_09 AC 704 ms
78,572 KB
testcase_10 AC 707 ms
78,496 KB
testcase_11 AC 695 ms
78,424 KB
testcase_12 AC 679 ms
78,272 KB
testcase_13 AC 686 ms
78,680 KB
testcase_14 AC 692 ms
78,476 KB
testcase_15 AC 692 ms
78,644 KB
testcase_16 AC 687 ms
78,480 KB
testcase_17 AC 694 ms
78,512 KB
testcase_18 AC 684 ms
78,728 KB
testcase_19 AC 687 ms
78,512 KB
testcase_20 AC 672 ms
78,600 KB
testcase_21 AC 697 ms
78,232 KB
testcase_22 AC 689 ms
78,720 KB
testcase_23 AC 700 ms
78,440 KB
testcase_24 AC 684 ms
78,592 KB
testcase_25 AC 681 ms
78,444 KB
testcase_26 AC 78 ms
71,048 KB
testcase_27 AC 592 ms
78,796 KB
testcase_28 AC 592 ms
78,620 KB
testcase_29 AC 585 ms
78,388 KB
testcase_30 AC 598 ms
78,444 KB
testcase_31 AC 584 ms
78,500 KB
testcase_32 AC 75 ms
71,408 KB
testcase_33 AC 358 ms
78,612 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):
	# 余裕みて少し大きめな数を取って、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