当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3197:Continuous Fractions

题目描述

A simple continuous fraction has the form:

where the ai’s are integer numbers.

The previous continuous fraction could be noted as [a1, a2, …, an]. It is not difficult to show that any rational number pq, with integers p > q > 0, can be represented in a unique way by a simple continuous fraction with n terms, such that pq = [a1, a2, …, an−1, 1], where n and the ai’s are positive natural numbers.

Your task is to find and print the simple continuous fraction that corresponds to a given rational number.

输入解释

Input will consist of a series of cases, each one in a line. A line describing a case contains p and q, two integer numbers separated by a space, with 1020 > p > q > 0.

The end of the input is indicated by a line containing 0 0.

输出解释

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 i by the corresponding case number. The second line displays the input data in the form p / q.

The remaining lines must contain the continuous fraction corresponding to the rational number, pq, specified in the given input line. The continuous fraction must be printed accordingly to the following rules:

  • Horizontal bars are formed by sequences of dashes ‘-’.
  • The width of each horizontal bar is exactly equal to the width of the denominator under it.
  • Blank characters should be printed using periods ‘.’.
  • 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.
输入样例
75 34
65 60
0 0
输出样例
Case 1:
75 / 34
..........1......
2.+.-------------
............1....
....4.+.---------
..............1..
........1.+.-----
................1
............5.+.-
................1
Case 2:
65 / 60
......1...
1.+.------
.........1
....11.+.-
.........1

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Colombia 2006

源链接: POJ-3197

最后修改于 2020-10-29T06:55:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536