All problems

Problem 346

Fraction to Recurring Decimal

Medium · 20 pts · Math, String, Hash Table

Problem

Write the fraction P / Q as a decimal. If the decimal part repeats forever, put the repeating block in parentheses, for example 1/3 = 0.(3) and 1/6 = 0.1(6). If the division is exact, print no parentheses (and no decimal point if the result is a whole number). Negative results start with '-'. Use long division and remember at which position each remainder first appeared: when a remainder repeats, the digits between the two occurrences repeat forever.

Input

Two integers P and Q.

Output

Print P / Q in decimal form.

Constraints

-2147483648 <= P, Q <= 2147483647; Q != 0

Example input

2 3

Example output

0.(6)

Explanation

2 / 3 = 0.6666..., where the digit 6 repeats forever, so it is written 0.(6).

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Multiples in a Range Next: Add Two Fractions