Under construction

Still being built. Things may change

Period

Time limit1sMemory limit1024 MB

Summary
Given a repeating decimal 0.(digits) with the repeating block written three times, print its value as a fully reduced fraction, numerator then denominator.
Level

Easy3 of 10

Topics
String, Math, Number theory
Solved
No attempts yet

Problem

Ivica likes decimal numbers. A decimal number has an integer part, a decimal point, and a fractional part. He especially likes numbers whose integer part is zero and whose fractional part is infinite, with some digits repeating periodically. For example, in 0.333... the digit 3 repeats forever, in 0.252525... the digits 25 repeat, and in 0.57424242... the digits 42 repeat.

A student from Cambridge wrote an article explaining how such decimals can be written as fractions. Let D be the decimal number, x the number of digits that do not repeat, and y the positive number of digits in the repeating part. For D = 0.064333..., x = 3 and y = 1. For D = 0.333..., x = 0 and y = 1. There are two cases.

Case 1: x = 0.

  1. Multiply D by 10y10^{y}.
  2. Subtract D from both sides.
  3. The numerator is the number on the right side, and the denominator is the number next to D.

Case 2: x > 0.

  1. Multiply D by 10x+y10^{x+y}.
  2. Multiply the original D by 10x10^{x}.
  3. Subtract the left sides of the two results from each other, and subtract their right sides from each other.
  4. The numerator is the number on the right side, and the denominator is the number next to D.

In both cases, the fraction must be reduced fully. A fraction is reduced fully when no natural number divides both the numerator and the denominator. If a number has more than one pair (x, y) that fits, choose the pair with the smallest y.

Input

The first line contains a real number D (0 < D < 1), the decimal number from the statement. The group of repeating digits appears exactly three times. It also holds that x + 3y <= 15.

Output

Print the numerator on the first line and the denominator on the second line of the fraction, reduced fully.

Examples5

  1. Example 1

    Input
    0.222
    
    Expected output
    2
    9
    
  2. Example 2

    Input
    0.252525
    
    Expected output
    25
    99
    
  3. Example 3

    Input
    0.123123123
    
    Expected output
    41
    333
    
  4. Example 4

    Input
    0.1222
    
    Expected output
    11
    90
    
  5. Example 5

    Input
    0.8161616
    
    Expected output
    404
    495