Among the fractions with positive denominators less than 1001, which one has the smallest difference from $\frac{123}{1001}$?
Solution. Let $p / q$ be the fraction with a positive integer denominator less than 1001, whose difference from 123/1001 is the smallest. Since 123 and 1001 are relatively prime, the latter fraction cannot be simplified, and thus

$$
\left|\frac{123}{1001}-\frac{p}{q}\right|=\left|\frac{123 q-1001 p}{1001 q}\right|=\delta
$$

cannot be zero. The numerator of the latter fraction is an integer, and thus, being non-zero, it is at least 1.

We distinguish two cases:

1. Case. $|123 q-1001 p| \geq 2$. In this case, due to the condition $1 \leq q \leq 1000$, the difference $\delta$ is at least $2 /(1001 q) \geq 1 /(1001 \cdot 500)$.
2. Case. $|123 q-1001 p|=1$. This can happen in two ways:
a) $123 q-1001 p=1$. Here $q$ and $p$ are positive integers and $q \leq 1000$, so $1001 p=123 q-1 \leq 122999$, and thus $p \leq 122$. We also see that $p$ is not divisible by three, because otherwise the left side would be divisible by three, but the right side would be 1. Thus, there are 82 possibilities for $p$, and by trying each of them, we find that only $p=94$ gives an integer for $q$: $q=765$. In this case, the fraction $p / q$ can only be $94 / 765$, and its difference from 123/1001 is $\delta=1 /(1001 \cdot 765)$.
b) $123 q-1001 p=-1$. This time, due to $q \leq 1000$, $1001 p=123 q+1 \leq 123001$, and thus $p$ can again be at most 122, and it is not divisible by three. This again gives 82 possibilities, and by trying each of them, we find that only $p=29$ gives an integer for $q$: $q=236$. The fraction $p / q=29 / 236$ has a difference from 123/1001 of $1 /(1001 \cdot 236)$.

Having examined all possibilities, the smallest difference occurs in case 2a), i.e., when $p / q=94 / 765$, so among the fractions with a positive integer denominator less than 1001, this fraction has the smallest difference from 123/1001.

Remark. The Diophantine equation $123 q-1001 p=1$ or -1 can also be solved in general, which would clearly lead to the solution of the problem. However, this also requires finding a specific solution, which can be done as described above, or by expanding the fraction 1001/123 into a continued fraction:

$$
\frac{1001}{123}=8+\frac{1}{7+\frac{1}{4+\frac{1}{4}}}
$$

The solution can be obtained by omitting the last fraction: choosing the denominator of $8+\frac{1}{7+\frac{1}{4}}=236 / 29$ as $p_{0}$ and its numerator as $q_{0}$, the general solution of the two equations is given by $p=123 r+p_{0}$ and $q=1001 r+q_{0}$, or $p=123 r-p_{0}$ and $q=1001 r-q_{0}$.