eolymp
bolt
Try our new interface for solving problems
Problems

Continuous Fractions

Continuous Fractions

A simple continuous fraction has the form: \includegraphics{https://static.e-olymp.com/content/9d/9d9e98e774e8eb14cda5825e5292375069b4be6a.jpg} where the \textbf{a_i}'s are integer numbers. \includegraphics{http://uva.onlinejudge.org/external/111/11113img2.png} \includegraphics{http://uva.onlinejudge.org/external/111/11113img2.png} The previous continuous fraction could be noted as \[\textbf{a_1}, \textbf{a_2}, ..., \textbf{a_n}\]. It is not difficult to show that any rational number , with integers \textbf{p} > \textbf{q} > \textbf{0}, can be represented in a unique way by a simple continuous fraction with \textbf{n} terms, such that = \[\textbf{a_1}, \textbf{a_2}, ..., \textbf{a_\{n-1\}}, \textbf{1}\], where \textbf{n} and the \textit{a}_i's are positive natural numbers. Your task is to find and print the simple continuous fraction that corresponds to a given rational number. \InputFile Input will consist of a series of cases, each one in a line. A line describing a case contains \textbf{p} and \textbf{q}, two integer numbers separated by a space, with \textbf{10^20} > \textbf{p} > q > \textbf{0}. The end of the input is indicated by a line containing \textbf{0 0}. \OutputFile Cases must be analyzed in the order that are read from the input. Output for each case will consist of several lines. The first line indicates the case number, starting at 1, using the format: Case i: replacing \textbf{i} by the corresponding case number. / The second line displays the input data in the form \textbf{pq}. \includegraphics{http://uva.onlinejudge.org/external/111/11113img2.png} The remaining lines must contain the continuous fraction corresponding to the rational number, , specified in the given input line. The continuous fraction must be printed accordingly to the following rules: \begin{itemize} \item Horizontal bars are formed by sequences of dashes '\textbf{-}'. \item The width of each horizontal bar is exactly equal to the width of the denominator under it. \item Blank characters should be printed using periods '\textbf{.}'. \item The number on a fraction numerator must be printed center justified. That is, the number of spaces at either side must be same, if possible; in other case, one more space must be added at the right side. \end{itemize} \includegraphics{https://static.e-olymp.com/content/7b/7b46308677c1cca07e38f78659b1301f52a24b1a.jpg}
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
75 34
0 0
Output example #1
Case 1:
75 / 34
..........1......
2.+.-------------
............1....
....4.+.---------
..............1..
........1.+.-----
................1
............5.+.-
................1