Consider the map $n\longmapsto ny/x$. You want to find a value of $n$ in a given range such that this is almost an integer. Such a point is encoded by an integral point of $\mathbb Z^2$ very close to the linear subspace generated by $(1,y/x)$. Closest points of this form are given by continued fraction approximations: Develop $x/y$ as a continued fraction and choose a convergent $a/b$ with $n=\lambda b$ in your range for small $\lambda$. This $n$ does the job.
If you want positive minimal values, then only every other convergent works. In your example, one gets convergents 1/4 and 2/7 and $4\cdot 17=68\equiv 7\pmod 61,\ 7\cdot 17\equiv -3\pmod 61$. Thus $n=7$ is a better solution but the smallest representant modulo $61$ of $7\cdot 17$ is negative.
Consider the map $n\longmapsto ny/x$. You want to find a value of $n$ in a given range such that this is almost an integer. Such a point is encoded by an integral point of $\mathbb Z^2$ very close to the linear subspace generated by $(1,y/x)$. Closest points of this form are given by continued fraction approximations: Develop $x/y$ as a continued fraction and choose a (small multiple of) a convergent $a/b$ with $n=\lambda b$ in your range . The denominator for small $b$ should then do \lambda$. This$n$does the job. 1 Consider the map$n\longmapsto ny/x$. You want to find a value of$n$in a given range such that this is almost an integer. Such a point is encoded by an integral point of$\mathbb Z^2$very close to the linear subspace generated by$(1,y/x)$. Closest points of this form are given by continued fraction approximations: Develop$x/y$as a continued fraction and choose a (small multiple of) a convergent$a/b$with$b$in your range. The denominator$b\$ should then do the job.