結果

問題 No.2368 I love a square root of 2
ユーザー shobonvipshobonvip
提出日時 2023-06-30 05:08:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,776 KB
実行使用メモリ 85,872 KB
最終ジャッジ日時 2023-09-20 23:44:24
合計ジャッジ時間 4,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
76,064 KB
testcase_01 AC 73 ms
75,952 KB
testcase_02 AC 219 ms
85,720 KB
testcase_03 AC 75 ms
75,992 KB
testcase_04 AC 74 ms
75,732 KB
testcase_05 AC 73 ms
75,696 KB
testcase_06 AC 75 ms
75,968 KB
testcase_07 AC 72 ms
75,928 KB
testcase_08 AC 76 ms
75,868 KB
testcase_09 AC 75 ms
75,872 KB
testcase_10 AC 76 ms
75,984 KB
testcase_11 AC 77 ms
75,864 KB
testcase_12 AC 76 ms
75,960 KB
testcase_13 AC 182 ms
83,664 KB
testcase_14 AC 186 ms
83,512 KB
testcase_15 AC 199 ms
84,476 KB
testcase_16 AC 154 ms
81,344 KB
testcase_17 AC 85 ms
76,996 KB
testcase_18 AC 85 ms
77,108 KB
testcase_19 AC 87 ms
76,968 KB
testcase_20 AC 87 ms
76,968 KB
testcase_21 AC 216 ms
85,872 KB
testcase_22 AC 212 ms
85,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cntunderk(k):
	y = 0
	cnt = 0
	for x in range(1, k+1):
		t = x * x
		while True:
			y += 1
			if 2 * y * y >= t:
				y -= 1
				break
		cnt += y + 1
	return cnt

n = int(input())
mx = 300000


ub = mx
lb = -1
while ub - lb > 1:
	k = (ub + lb) // 2
	if cntunderk(k) < n:
		lb = k
	else:
		ub = k

y = 0
s = []
for x in range(lb, -1, -1):
	while True:
		if 2 * y * y < (lb - x) * (lb - x):
			y += 1
			continue
		break
	assert 2 * y * y >= (lb - x) * (lb - x)
	if 2 * y * y < (lb + 1 - x) * (lb + 1 - x):
		s.append((x, y))

sqrt2 = 2 ** 0.5

s.sort(key = lambda x : x[0] + x[1] * sqrt2)
n -= cntunderk(lb)
assert n >= 1
assert n <= len(s)
print(*s[n-1])
0