#P2118. Simplified Ratio Approximation
Simplified Ratio Approximation
Simplified Ratio Approximation
In social media surveys, participants are asked if they agree or disagree with a statement. For example, 1498 people may support a view while 902 oppose it, giving a raw ratio of 1498:902. However, such large numbers are not visually intuitive. A simplified ratio like 5:3 might be preferable even if it introduces some error.
You are given three integers: the number of people in favor A, the number of people against B, and an upper limit L. Your task is to simplify the ratio A:B into A':B' such that:
- Bounds: Both A' and B' are at most L.
- Irreducibility: A' and B' are coprime (their greatest common divisor is 1).
- Approximation Condition: The simplified ratio must satisfy \(\frac{A'}{B'} \ge \frac{A}{B}\).
- Minimal Error: The value \(\frac{A'}{B'} - \frac{A}{B}\) should be as small as possible.
Note that if the original ratio A:B (when expressed in simplest form) already satisfies the bounds, then it may be the optimal answer.
Formula Note: All mathematical formulas are given in \(\LaTeX\) format.
inputFormat
The input consists of a single line containing three integers separated by spaces:
A
: the number of people in favor.B
: the number of people against.L
: the maximum allowed value for both numerator and denominator in the simplified ratio.
\(1 \le A, B, L \le 10^4\) (constraints are given for example purposes).
outputFormat
Output two integers A'
and B'
separated by a space representing the simplified ratio that meets all the conditions.
sample
1498 902 10
5 3
</p>