Let b0, b1, b2, . . . , bn be integers with bk > 0 for k > 0. The continued fraction of order n with coeficients b1, b2, . . . , bn and the initial term b0 is defined by the following expression b0 + 1 b1 + 1 b2+...+ 1 bn which can be abbreviated as [b0; b1, . . . , bn]. An example of a continued fraction of order n = 3 is [2; 3, 1, 4]. This is equivalent to 2 + 1 3 + 1 1+ 1 4 = 43 19 Write a program that determines the expansion of a given rational number as a continued fraction. To ensure uniqueness, make bn > 1.
The input consists of an undetermined number of rational numbers. Each rational number is defined by two integers, numerator and denominator.
For each rational number given in the input, you should output the corresponding continued fraction.
範例輸入 1
43 19 1 2
範例輸出 1
[2;3,1,4] [0;2]
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.