eolymp
bolt
Try our new interface for solving problems
Problems

Rational Numbers from Repeating Fractions

Rational Numbers from Repeating Fractions

\includegraphics{https://static.e-olymp.com/content/5d/5dce1924eed256522b4377b553b32cb5997fe2bd.jpg} A rational number is any which can be written in the form \textbf{p}/\textbf{q}, where \textbf{p} and \textbf{q} are integers. All rational numbers less than \textbf{1} (that is, those for which \textbf{p} is less than \textbf{q}) can be expanded into a decimal fraction, but this expansion may require repetition of some number of trailing digits. For example, the rational number \textbf{7}/\textbf{22} has the decimal expansion \textbf{.3181818}... Note that the pair of digits \textbf{1} and \textbf{8} repeat ad infinitum. Numbers with such repeating decimal expansions are usually written with a horizontal bar over the repeated digits, like this: . If we are given the decimal expansion of a rational fraction (with an indication of which digits are repeated, if necessary), we can determine the rational fraction (that is, the integer values of \textbf{p} and \textbf{q} in \textbf{p}/\textbf{q}) using the following algorithm. Assume there are \textbf{k} digits immediately after the decimal point that are not repeated, followed by a group of \textbf{j} digits which must be repeated. Thus for \textbf{7}/\textbf{22} we would have \textbf{k} = \textbf{1} (for the digit \textbf{3}) and \textbf{j} = \textbf{2} (for the digits \textbf{1} and \textbf{8}). Now if we let \textbf{X} be the original number (\textbf{7}/\textbf{2}2), we can compute the numerator and denominator of the expression \includegraphics{https://static.e-olymp.com/content/07/074e25e036a245fe1bad0d31da9f0506af051b77.jpg} For we obtain the following calculation for the numerator of this fraction: \includegraphics{https://static.e-olymp.com/content/b4/b4d1b0add4e5a434e5bc7e4e44eb27929aa092ca.jpg} The denominator is just \textbf{1000} - \textbf{10}, or \textbf{990}. It is important to note that the expression in the numerator and the denominator of this expression will always yield integer values, and these represent the numerator and denominator of the rational number. Thus the repeated fraction is the decimal expansion of the rational number \textbf{315}/\textbf{990}. Properly reduced, this fraction is (as expected) just \textbf{7}/\textbf{22}. \InputFile - The input data for this problem will be a sequence of test cases, each test case appearing on a line by itself, followed by \textbf{a} \textbf{1}. Each test case will begin with an integer giving the value of \textbf{j}, one or more spaces, then the decimal expansion of a fraction given in the form \textbf{0.ddddd} (where \textbf{d} represents a decimal digit). There may be as many as nine (\textbf{9}) digits in the decimal expansion (that is, the value of \textbf{k}+\textbf{j} may be as large as \textbf{9}). \OutputFile For each test case, display the case number (they are numbered sequentially starting with \textbf{1}) and the resulting rational number in the form \textbf{p}/\textbf{q}, properly reduced.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2 0.318
1 0.3
2 0.09
6 0.714285
-1
Output example #1
Case 1: 7/22
Case 2: 1/3
Case 3: 1/11
Case 4: 5/7