|
|||
Long DivisionOne thing Harry, Ron, and Hermione have learned at Hogwarts is that you must be precise in everything you do. After all, if you wish to transfigure yourself into a lion, it does no good to change into a kittycat, even though they are approximately the same! With this in mind, Harry has gotten pretty fed up with his calculator that only does long division to 8 places! You are to write a program to perform long division with infinite precision. Input SpecificationEach line will consist of two nonnegative decimal integers no greater than 10000, separated by exactly one space, and followed by one or more newline characters. The first is the numerator; the second is the denominator. The last line in the input will feature a denominator of zero. This line is not to be processed; it only signals the end of the input. Output SpecificationThe output cases are to appear in the same order in which they appear in the input. Each case should appear as follows: the numerator, a slash, the denominator, a space, the equals sign, another space, and the answer. If the answer contains no remainder, the answer should simply be a nonnegative decimal integer (without a decimal point). If there is a remainder, the answer should appear as the integer portion, a decimal point, and the decimal portion. If the decimal terminates, the decimal portion is simply the string of digits that follow the decimal point. If the decimal repeats, the repeating portion should be enclosed in parentheses. Note that you must enclose the earliest repeating portion in parentheses: 1/11 = 0.(09), not 0.0(90). Terminating decimals are to be printed as terminating decimals: 1/2 = 0.5, not 0.5(0), or 0.4(9), even though these three are mathematically equivalent. There is a line width of 50; any line greater than 50 characters must be broken into lines each containing 50 characters, excepting the last which will contain however many are left over. Following the answer should be two newline characters, one to terminate the line, and one to skip a line. Sample Input
Output for Sample Input
Original Problem |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |