TITLE: Minimal $ab$ for Rational Number $a/b$ in an Interval
QUESTION [11 upvotes]: Given rational numbers $L$ and $U$, $0<L<U<1$, find rational number $M=a/b$ such that $L \le M<U$ and $(a\times b)$ is as small as possible---$a$ and $b$ are integers. For example, 

If $L=66/101$ and $U=19/29$ then $M=17/26$.
If $L=66/101$ and $U=19/28$ then $M=2/3$.

Right now I'm using a naive search that is exponential in complexity.
Is there a better method?
If it is of any help, it can be assumed the prime factorization of numerator and
denominator of $U$ and $L$ are known.

REPLY [5 votes]: As per TonyK's answer, it is only necessary to find the smallest denominator for which a fraction in $[L,U)$ exists.
To avoid what he calls "messy" oscillations, we can proceed as follows:

Start with $(a,b,c,d)=(0,1,1,1)$. 
*[Remark: We have $\frac ab<L<U\le \frac cd$, and $ad-bc=-1$, and any fraction between $\frac ab$ and $\frac cd$ has denominator $\ge b+d$]*$\quad$  Let $u\leftarrow a+c$, $v\leftarrow b+d$.
If $u<Lv$, let $a\leftarrow u$, $b\leftarrow v$ and go to step 2
If $u\ge Uv$, let $c\leftarrow u$, $d\leftarrow v$ and go to step 2.
We have found $M=\frac uv$ for which the product $uv$ is minimal. Terminate