Why does the integral work for this sum? Suppose we have the following sum: $$ \sum_{n=1}^{1010^2} \frac{1}{\sqrt{n}} $$ and we want to calculate the very next integer greater than this.
Then one may take the integral, $$ \int_1^{1010^2} \frac{1}{\sqrt{x}}$$ and calculate it to be $2018$, so the very next integer greater than this is $2019$. Why does the integral work so well here?
I know the integral is equal to the sum of $$ f(x) \delta x$$ as $x$ tends to zero, but I still can’t derive how the integral works so well here. I lack intuition, I think.
 A: HINT
$$\frac1{\sqrt{k+1}}<\int_k^{k+1}\frac{\mathrm{d}x}{\sqrt x}<\frac1{\sqrt{k}}$$
Can you do it now?
A: You can also use generalized harmonic numbers $$S_p=\sum_{n=1}^{p^2} \frac{1}{\sqrt{n}}=H_{p^2}^{\left(\frac{1}{2}\right)}$$ Using their asymptotics
$$S_p=2 p+\zeta \left(\frac{1}{2}\right)+\frac{1}{2 p}-\frac{1}{24
   p^3}+O\left(\frac{1}{p^7}\right)$$ Using the "exact" value of $\zeta \left(\frac{1}{2}\right)$ and $p=1010$, the truncated expansion gives
$$S_{1010}\sim \color{blue}{2018.54014054065492242599635}394$$ while the "exact" value is $$S_{1010}\sim \color{blue}{2018.54014054065492242599635638}$$
A: The terms of the sum are
$$\frac1{\sqrt n}$$ vs. those of the integral $$\int_n^{n+1}\frac{dx}{\sqrt x}=2{\sqrt{n+1}}-2{\sqrt{n}}\approx2\sqrt n\left(1+\frac1{2n}-\frac1{8n^2}+\frac1{16n^3}-\cdots\right)-2\sqrt n
\\=\frac1{\sqrt n}-\frac1{4n\sqrt n}+\frac1{8n^2\sqrt n}-\cdots$$
When you sum from $1$ to $1010^2$, the first error term is close to $$\frac14\zeta\left(\frac32\right)=0.653094\cdots,$$ which is less than $1$. As the error terms alternate in sign, the global error is even smaller.
