TITLE: How to evaluate a sum of square roots rounded to the nearest integer?
QUESTION [5 upvotes]: This is (adapted from) Problem 11 from the 2007 AIME :

For each positive integer $p$, let $b(p)$ denote the unique positive integer $k$ such that $|k-\sqrt{p}|<\frac{1}{2}$. For example, $b(6)=2$ and $b(23)=5$. Find $S=\sum_{p=1}^{2007} b(p)$.

I started by noting that 
$$\left(k- \frac 12\right)^2=k^2-k+\frac 14\text{ and }\left(k+ \frac 12\right)^2=k^2+k+ \frac 14.$$
So, all numbers from $1-44$ will have the maximum value in the range.
How should I continue, or approach the problem.

REPLY [4 votes]: If you try out a few numbers, you start to see the pattern, namely
$$11222233333344444444....$$
Each number $n$ appears $2n$ times. That is, $n$ appears between $n^2 - n  + 1$ and $n^2 + n$ inclusive. It ends when $n = 45$, which corresponds to the range
$45^2 - 45 + 1 = 1981$ to $45^2 + 45 = 2070$, but since you cut off at $p = 2007$ you only include $45$ a total of $27$ times. So your sum is
$$\sum_{n = 1}^{44} 2n^2 + 45*27$$
Using the formula $\sum_{n=1}^k n^2 = {k(k+1)(2k+1) \over 6}$, we get
$$\sum_{n = 1}^{44} 2n^2 + 45*27 = {44*45*89 \over 3} + 45*27$$
$$= 58740 + 1215$$
$$= 59955$$
Not sure how a high school kid is supposed to do it on a timed exam, but this is pretty elementary at least.