TITLE: sums involving the nearest-integer function
QUESTION [5 upvotes]: Let $r$ be a positive real number.  For each positive integer $n$, let $y = m_n x + b_n$ be the line that best approximates (in the least-squares sense) the set of $n$ points $(k,{\rm nint}(kr))$ with $1 \leq k \leq n$, where ${\rm nint}$ is the nearest integer function.  Does the difference between $m_n$ and $r$ go to zero like $O(1/n^2)$?
Failing an answer to that question, I'd welcome pointers to any known bounds on the difference between $\sum_{k=1}^n {\rm nint}(kr)$ and $\sum_{k=1}^n kr$ as well as bounds on the difference between $\sum_{k=1}^n k \: {\rm nint}(kr)$ and $\sum_{k=1}^n k^2r$, since these could be used to answer the above question.

REPLY [3 votes]: The error term depends on continued fraction expansion of $r$. It is Khinchine's theorem. In the simple case (when $r=[q_0;q_1,q_2,...]$ is a Liouville number with convergents $P_k/Q_k$) for $n=Q_k$ the error term will has the following form
$$\frac{q_1+\cdots+q_k}{Q_k}\asymp \frac{q_k}{Q_k}.$$ It can be $\gg Q_k^{-\varepsilon}=n^{-\varepsilon}$ for some fast growing $q_k$.