Joint Attack
InterviewTime limit1sMemory limit512 MB
Convert a continued fraction given as coefficients into a single reduced fraction, with numerator and denominator under 10^18.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Number theory, Simulation
- Solved
- No attempts yet
Problem
General Torstein has sent the x-coordinate for the next joint attack and expects you to follow his orders promptly to avoid impending doom. Unfortunately Torstein hates numbers with more than 2 digits and loves horizontal line segments, so he sent the coordinate as a continued fraction, that is,
[ x=x_0+\frac{1}{x_1+\frac{1}{\ldots}} ]
Your rocket launcher only accepts coordinates as reduced fractions, so you need to compute the correct numbers quickly to feed it before the attack can begin. Hurry! Failure may have dire consequences!
Input
The first line contains one integer n (1 ≤ n < 40), the number of coefficients in the continued fraction. The next line contains n integers (1 ≤ xi < 100), the coefficients of x.
Output
Print the coordinate x as a reduced fraction. It is guaranteed that the numerator and denominator are both less than 1018.