#P1298. 最接近的分数

最接近的分数

Description

Given a positive decimal number, find a reduced fraction or an integer whose numerator (numerator 0 \ge 0) does not exceed MM and denominator does not exceed NN, 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 22 lines of input. The first line contains two space-separated positive integers MM and NN, indicating that the fraction’s numerator does not exceed MM and the denominator does not exceed NN. The second line contains a decimal R(R>0)R(R>0); the integer part of RR is a single Arabic digit, and the fractional part has at most ten digits.

Output Format

Output exactly 11 line. If the solution is unique, output numerator/denominator (an integer KK should be written as K1\dfrac{K}{1}); otherwise output TOO MANY.

360 120
3.1415926536

355/113

Hint

Constraints

For all testdata, it is guaranteed that 1M,N1071\le M,N\le 10^7.

Translated by ChatGPT 5