Continued Fractions#1023

Continued Fractions

1 second
128 megabytes
Very easy

Let b_0, b_1, b_2, , b_n be integers such that b_k > 0 for k > 0. The continued fraction of order with coefficients b_1, b_2, , b_n and initial term b_0 is defined by the following expression:

b_0 + \cfrac{1}{b_1 + \cfrac{1}{b_2 + \cfrac{1}{\ddots + \cfrac{1}{b_n}}}}

This expression can be abbreviated as [b_0; b_1, \ldots, b_n].

For example, a continued fraction of order n=3 with [2;3,1,4] is equivalent to:

2 + \cfrac{1}{3 + \cfrac{1}{1 + \cfrac{1}{4}}}

Write a program that finds the continued fraction expansion for a given rational number. To ensure uniqueness, b_n > 1.

Input

The input consists of an undetermined number of rational numbers. Each rational number is given as a fraction: numerator and denominator.

Output

For each rational number, output its continued fraction representation on a separate line.

Examples

Example 1

Loading
Loading