TITLE: Estimating $\sum n^{-1/2}$
QUESTION [6 upvotes]: Could someone please explain me how does one obtain the following estimate:
$$
\sum_{n \leq X} n^{-1/2} = \frac12 X^{1/2} + c + O(X^{-1/2}),
$$
where $c$ is some constant.
Thank you very much!
PS As pointed out in the comments, $1/2$ in front of $X^{1/2}$ is a typo... I would like an answer with the correct coefficient here.

REPLY [4 votes]: Denote $f(x)=x^{-1/2}, \ S_n=\sum_{k=1}^nf(k)$. Using the mean value theorem we obtain that $f(x)=f(k)+(x-k)f'(x_k)$, for $x\in[k,k+1]$ where $x_k\in(k,k+1)$, thus 
\begin{align*}
\int_{1}^{n+1}f(x)dx-S_n=\sum_{k=1}^n\int_{k}^{k+1}(f(x)-f(k))dx=\sum_{k=1}^n\int_{k}^{k+1}(x-k)f'(x_k)dx=\frac{1}{2}\sum_{k=1}^nf'(x_k).
\end{align*}
Since
\begin{align*}
\int_{1}^{n+1}f(x)dx=2n^{1/2}-2
\end{align*}
and
\begin{align*}
\Big|\sum_{k=n+1}^{\infty}f'(x_k)\Big|\leq\int_{n}^{\infty}|f'(x)|dx= f(n)=n^{-1/2}
\end{align*}
we obtain
\begin{align*}
S_n=2n^{1/2}-2-\frac{1}{2}\sum_{k=1}^{\infty}f'(x_k)+\sum_{k=n+1}^{\infty}f'(x_k)=2n^{1/2}+c+O(n^{-1/2}).
\end{align*}
Comment: to get better expression for c use Taylor formula of second order: $f(x)=f(k)+(x-k)f'(k)+(x-k)^2/2f''(k)$.