Repeating Decimals

Time limit1sMemory limit128 MB

Summary
Convert each repeating decimal with its repeating part in parentheses into a reduced fraction printed beside the input.
Level

Medium4 of 10

Topics
Math, Number theory
Solved
No attempts yet

Problem

Any fraction can be written as a decimal. For example, 12\frac{1}{2} is 0.50.5, and 13\frac{1}{3} is 0.333…0.333\dots, which is written more compactly as 0.3‾0.\overline{3}. The digits of 0.50.5 stop, while the digits of 0.3‾0.\overline{3} repeat forever. Here are some fractions written as repeating decimals.

27=0.285714‾1766=0.2575‾\frac{2}{7} = 0.\overline{285714} \qquad \frac{17}{66} = 0.25\overline{75}

256=4.16‾3401333=10.213‾\frac{25}{6} = 4.1\overline{6} \qquad \frac{3401}{333} = 10.\overline{213}

Given a repeating decimal, write a program that finds the fraction with the same value. The numerator and the denominator must be coprime.

Input

The input holds several test cases and continues to the end of the file. Each line contains one repeating decimal. The part that repeats forever is wrapped in parentheses, so 0.25(75) means 0.25757575…0.25757575\dots. Each decimal contains at most 9 digits.

Output

For each test case, print the fraction with the same value as the given decimal on its own line. The format is given decimal = numerator / denominator, with one space on each side of the equals sign and of the slash. The numerator and the denominator must be coprime, and when the value is an integer the denominator is 1.

Examples1

  1. Example 1

    Input
    0.(285714)
    0.25(75)
    4.1(6)
    
    Expected output
    0.(285714) = 2 / 7
    0.25(75) = 17 / 66
    4.1(6) = 25 / 6