#P3610. Maclaurin Series of Reciprocals

Maclaurin Series of Reciprocals

Description

Any function f(x) that is infinitely differentiable in the neighborhood of the point x = 0 can be expanded into a Maclaurin series

f(0)+\frac{f'(0)}{1!}x+\frac{f''(0)}{2!}x^2+\frac{f^{(3)}(0)}{3!}x^3+\cdots,

or more compactly,

\sum_{k=0}^{\infty}\frac{f^{(k)}(0)}{k!}x^k.

Under certain conditions, f(x) is equal to its Maclaurin series for all x sufficiently close to 0.

Often, the Maclaurin series of f(x) is written up to only order xn-1 with a Peano remainder term, i.e., 

\sum_{k=0}^{n-1}\frac{f^{(k)}(0)}{k!}x^k+\mathcal{O}(x^n),

which facilitates the evaluation of f(x). The series being truncated to the xn-1 term, details about higher-order terms are inevitably lost. However, certain information concerning the series remains well-preserved. For instance, the Maclaurin series of 1/f(x) with an identical Peano remainder term can still be found.

Given the Maclaurin series of a function f(x) with a Peano remainder term, determine that of the reciprocal of f(x).

Input

The input consists of a single test case.

The first line contains an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a fraction pk/qk (0 ≤ k ≤ n - 1) where pk and qk (-100 ≤ pk ≤ 100, 1 ≤ qk ≤ 100) are integers coprime to each other in the form either pk/qk (if qk ≠ 1) or pk (if qk = 1). It is guaranteed that p0 ≠ 0.

The given numbers represent the Maclaurin series

\sum_{k=0}^{n-1}\frac{p_k}{q_k}x^k+\mathcal{O}(x^n)

of some function f(x).

Output

Let the Maclaurin series of 1/f(x) be

\sum_{k=0}^{n-1}\frac{p'_k}{q'_k}x^k+\mathcal{O}(x^n)

where qk' > 0, and pk' and qk' are integers coprime to each other. Output n lines each of the form either pk'/qk' (if qk' ≠ 1) or pk' (if qk' = 1), listing the coefficients of 1, x, x2, ... , xn-1 in order.

10
1/2
-46/3
9/40
61/80
-22/5
-87/41
1/11
-42/5
-4/13
-21/44
2
184/3
169199/90
6223213/108
28611844561/16200
107867589093163/1992600
545525329585163771/328779000
401297234058997162673/7890696000
2398505849871035056778279/1538685720000
882189800570641237196128639/18464228640000

Source

POJ Founder Monthly Contest – 2008.06.29

, frkstyc