Rational Approximation
Time limit1sMemory limit128 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
A polynomial of degree can be used to approximate a function by setting the coefficients of to match the leading coefficients of the power series of (expanded about ). For example,
Unfortunately, polynomials are "nice" and do not work well when approximating functions that behave poorly (for example, functions with singularities). To overcome this, we can instead approximate by a rational function of the form , where and are polynomials.
Given , , and the first coefficients of the power series of , compute two polynomials and of degrees at most and , respectively, such that the power series expansion of has as its first coefficients and as the coefficient of the term. In other words, find and such that
where contains terms with powers of higher than . From this, can be approximated by .
Input
The input consists of multiple cases. Each case is given on one line in the form
m n f0 f1 ... f(m+n-1)
where is the coefficient of in the power series expansion of . You may assume that , , , and that each is an integer with . The end of input is indicated by a line containing with no coefficients for . You may assume that the solution for each input is unique.
Output
For each test case, print two lines. Print the polynomial on the first line and on the second line.
Print the polynomial as a list of pairs arranged in ascending order of , where is a non-zero coefficient of the term. Print each non-zero coefficient as , where and is in lowest terms; if , print only (omit ). If , print a line containing only . Separate the pairs in the list by a single space.
Print the polynomial in the same manner. Insert a blank line between cases.
Hint
A polynomial can be written as , and likewise for . In this problem the coefficients and are rational numbers.
The power series expansion of about can be written as , where the are integers in this problem.