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.
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: