The following is an exercise from my textbook. I can't really seem to find similar examples in the book and I find it a bit confusing.
I need to find a closed form expression for $$\sum_{k=0}^n \left \lceil\sqrt{2k} \right\rceil, \quad n \ge 0$$
attempt thus far,
Let $q=\lceil \sqrt{2k}\rceil$ Then,
\begin{align*} \sum_{k=0}^n \left \lceil\sqrt{2k} \right\rceil &= \sum_{0\leq k<n}\left \lceil\sqrt{2k} \right\rceil \\ &= \sum_{k, q \geq 0}q [k<n][q-1 < \sqrt{2k} \leq q] \\ &= \sum_{k, q \geq 0}q [k<n][(q-1)^2 < 2k \leq q^2] \\ &= \sum_{k, q \geq 0}q [k<n][\frac{(q-1)^2}{2} < k \leq \frac{q^2}{2}] \\ &= \sum_{k, q \geq 0}q[\frac{(q-1)^2}{2} < k \leq \frac{q^2}{2} < n] \\ &= \quad ... \end{align*}
Hint:
$\left\lceil\sqrt{2k}\right\rceil$ remains constant between two perfect squares, i.e. when
$$(m-1)^2<2k\le m^2.$$
These intervals have length $2m-1$, so that the contributions of all the complete intervals are
$$\sum_{j=1}^{m}(j^2-(j-1)^2)j=\sum_{j=1}^{m}(2j-1)j$$
where $m$ is the largest integer such that $m^2\le2n$.
The last interval is usually incomplete and contributes $(n-m)(m+1)$.