编程介的小学生 2017-01-10 16:46 采纳率: 20.5%
浏览 937
已采纳

Continuous Fractions

Description

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 p⁄q, with integers p > q > 0, can be represented in a unique way by a simple continuous fraction with n terms, such that p⁄q = [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

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.

Output

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, p⁄q, 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.
Sample Input

75 34
65 60
0 0
Sample Output

Case 1:
75 / 34
..........1......
2.+.-------------
............1....
....4.+.---------
..............1..
........1.+.-----
................1
............5.+.-
................1
Case 2:
65 / 60
......1...
1.+.------
.........1
....11.+.-
.........1

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-01-16 15:37
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?