Does anyone know a reference to best-fitting lines with integral coefficients?

147 Views Asked by At

I'm writing up a manual on how to generate "nice" Linear Algebra problems; that is, where the solutions tend to be integral. I "discovered" the following fact about the best-fitting line:

Theorem. Let $x_1,x_2,\ldots,x_n$ be integers such that (a) $\displaystyle\sum_{i=1}^n x_i=0$, and (b) $x_i\not=x_j$ for some $i,j$. Then the best-fitting line $y=ax+b$ for the data points $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$ has integral coefficients iff $$\sum_{k=1}^n x_i y_i \equiv 0 \pmod {\sum_{i=1}^n {x_i}^2} \quad\quad\quad\quad{\rm and}\quad\quad\quad\quad \sum_{k=1}^n y_i \equiv 0 \pmod {n}.$$

This is the sort of result which is nice, was probably discovered before, and which I cannot find any reference to. Has anyone seen this in a paper anywhere?