P1298 Closest Fraction
Description
Given a positive decimal number, find a reduced fraction or an integer whose numerator (numerator $ \ge 0$) does not exceed $M$ and denominator does not exceed $N$, such that it is closest to the given decimal on the number line. If this closest fraction is not unique, output ``TOO MANY``.
Input Format
There are $2$ lines of input. The first line contains two space-separated positive integers $M$ and $N$, indicating that the fraction’s numerator does not exceed $M$ and the denominator does not exceed $N$. The second line contains a decimal $R(R>0)$; the integer part of $R$ is a single Arabic digit, and the fractional part has at most ten digits.
Output Format
Output exactly $1$ line. If the solution is unique, output `numerator/denominator` (an integer $K$ should be written as $\dfrac{K}{1}$); otherwise output ``TOO MANY``.
Explanation/Hint
### Constraints
For all testdata, it is guaranteed that $1\le M,N\le 10^7$.
Translated by ChatGPT 5