DWITE Online Computer Programming Contest, November 2010, Problem 4
In math class, writing fractions in their decimal form was a common task. However, the teachers would usually have you round off the number to a certain number of decimal places. But all fractions have a nice property: in decimal form, they all either terminate or repeat in a pattern. For example, the fraction terminates, as . However, the fraction repeats, as (note that the repeated part is parenthesized). Given a fraction, output its decimal form, parenthesizing the cyclic part of the fraction, if such exists.
The input will contain 5 lines, each a pair of integers , separated by a single space.
The output will contain 5 lines, the decimal forms of , truncating and parenthesizing the repeating digits, if such is the case.
Note: the answers must match exactly and use the shortest repeating pattern. Since is always greater than , all of the answers are less than .
Sample Input
1 10
1 3
2 7
2 3
6 10
Sample Output
0.1
0.(3)
0.(285714)
0.(6)
0.6
Problem Resource: DWITE
Comments