Exact? Approximate!
ID:
1165
DescriptionDifferent people have different notions of entertainment. Some need the most incredible
gadgets to play with, others are able to find pleasure in common everyday devices.
This problem is dedicated to those, who have ever been amused by a pocket calculator
(which is, unofficially, considered to be the 23rd most entertaining invention in
the modern history of mankind).
One of the most popular calculator games has the following rules. Given a positive
number X with D digits after the decimal point. Your task is to find
a fraction A/B (where A and B are positive integers), that
approximates the number X. More exactly, the value of A/B rounded
to D digits after the decimal point must be exactly X. Moreover, we
require that B is as small as possible. Note that the fraction A/B
we seek is now unique.
Common rounding rules apply, i.e. 0-4 rounds down, 5-9 up. Thus:
1/3 rounded to 3 decimal places is 0.333
2/3 rounded to 3 decimal places is 0.667
5/10000 rounded to 3 decimal places is 0.001
5/10001 rounded to 3 decimal places is 0.000
InputEach test case contains one positive
real number Xi in decimal notation. You can assume that Xi is less
than one. Note that trailing zeroes are significant.
OutputFor each test case, output two positive integers A and B (separated by
a single space character), such that the fraction A/B meets the requirements
stated above.
Sample Test Cases| Input | Expected Output |
|---|
0.333333333333333333333 | 1 3 |
0.40000000 | 2 5 |
0.7 | 2 3 |
0.70 | 7 10 |

Loading...
Statistics
The Tops
No Submissions