結果

問題 No.2177 Recurring ab
ユーザー MasKoaTSMasKoaTS
提出日時 2022-11-18 19:23:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 81,900 KB
実行使用メモリ 53,760 KB
最終ジャッジ日時 2023-10-20 04:47:45
合計ジャッジ時間 2,980 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,760 KB
testcase_01 AC 37 ms
53,700 KB
testcase_02 AC 38 ms
53,760 KB
testcase_03 AC 37 ms
53,760 KB
testcase_04 AC 37 ms
53,760 KB
testcase_05 AC 37 ms
53,760 KB
testcase_06 AC 37 ms
53,760 KB
testcase_07 AC 37 ms
53,760 KB
testcase_08 AC 38 ms
53,760 KB
testcase_09 AC 37 ms
53,760 KB
testcase_10 AC 37 ms
53,760 KB
testcase_11 AC 37 ms
53,760 KB
testcase_12 AC 38 ms
53,760 KB
testcase_13 AC 38 ms
53,760 KB
testcase_14 AC 37 ms
53,760 KB
testcase_15 AC 38 ms
53,760 KB
testcase_16 AC 37 ms
53,760 KB
testcase_17 AC 39 ms
53,760 KB
testcase_18 AC 37 ms
53,760 KB
testcase_19 AC 37 ms
53,760 KB
testcase_20 AC 36 ms
53,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
from itertools import permutations
input = sys.stdin.readline

def ceil_sqrt(n):
	rn = math.sqrt(n)
	ok = max(0, int(rn - 2))
	ng = int(rn + 2)
	while(ng - ok > 1):
		k = (ok + ng) >> 1
		if(k * k <= n):
			ok = k
		else:
			ng = k
	return ok + (ok ** 2 != n)


n = int(input())

def check(p, a, b):
	return (p ** 2 < n * (p * a + b) + 1)

ans = 0
for a, b in permutations([*range(10)], 2):
	min_p = max(a, b) + 1
	if not(check(min_p, a, b)):
		continue
	left = min_p * 2
	right = n * a + ceil_sqrt((n * a) ** 2 + 4 * (n * b + 1))
	ans += ((right - left) >> 1) + (right & 1)
print(ans)
0