Treating Fractions Irrationally
Time limit2sMemory limit512 MB
Write the decimal of n/d cut off at the first 0 or 9, rounding down at 0 and up at 9, or throw it out if neither digit ever appears.
- Level
Medium4 of 10
- Topics
- Math, Simulation, Implementation
- Solved
- No attempts yet
Problem
Anna writes reports packed with statistics, and she cannot stand fractions. Instead of writing she writes the decimal form
That creates two problems. The decimal form usually has to be cut off somewhere, and once it is cut off it is no longer equal to the fraction. Anna keeps the second problem small with one rule: she writes the decimal form up to but not including the first digit that is or , rounding down when that digit is and rounding up when it is .
Under that rule becomes , and becomes . When the very first digit after the decimal point is , as in , Anna writes just . When the very first digit after the decimal point is , as in , she writes just . When neither nor ever appears in the decimal form, as in , Anna throws the value out.
The decimal form is the one long division produces, so a fraction that terminates is followed by zeros forever. is , and Anna writes it as .
Input
The input is one line with two positive integers and separated by a space. ()
Output
Print Anna's version of . If the decimal form of contains neither the digit nor the digit , print throw out instead.