sums involving the nearest-integer function 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.
 A: 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$.
A: I know very little about mean square approximation, so I will focus on the sums.  A very partial answer is that, for $r$ rational and not $2$-integral, the sums $\sum_{k=1}^n \text{nint}(kr)-kr$ and $\sum_{k=1}^n k(\text{nint}(kr)-kr)$ will be $\Theta(n)$ and $\Theta(n^2)$, respectively.  This comes from conventions needed to break ties and is specific to the case where $r$ is rational and has denominator divisible by $2$.  For the first sum with $r$ rational and $2$-integral, the sum will be $O(1)$.  A very naive argument using Weyl's equidistribution shows that, for $r$ irrational, the value of $\frac1n\sum_{k=1}^n(kr - \text{nint}(kr)) \rightarrow\int_0^1(x-\text{nint}(x))dx = 0$, so there is an error of at most $o(n)$.  For the second sum, the best error that you can get with $r$ not integral is $O(n)$, as, for $r$ rational, the value of $kr - \text{nint}(kr)$ is periodic in $k$, while, for $r$ irrational there will regularly be values of $kr - \text{nint}(kr)$ arbitrarily near $\frac12$, so there will be contributions of at least $Ck$ in the second sum infinitely often.
