How to find a point with positive integer coordinates which is closest to a line?

1.1k Views Asked by At

Given the equation of a line, we need to find a point with positive integer coordinates$^*$ such that the distance of that point from the line is a minimum.

How can we go about it?

$^*$ i.e. both the $x$ and $y$ coordinates are positive integers

1

There are 1 best solutions below

6
On

If the slope is irrational and the line does not go through integer points, you can't. There will be integer points arbitrarily close to the line. If the slope is rational, the distances will repeat with period the denominator of the slope. If the slope is less than $1$ in absolute value, you can look at its inverse by making $x$ a function of $y$ and the repeat will be shorter.