ICPC ECNA 2000 C - Rational Approximation
View as PDFICPC East Central NA Regional Contest 2000, Problem C
A polynomial  of degree 
 can be used to approximate a function 
 by setting the coefficients of 
 to match the first 
 coefficients of the power series of 
 (expanded about 
). For example,
Unfortunately, polynomials are "nice" and they do not work well when they are used to approximate functions that behave poorly (e.g. those with singularities). To overcome this problem, we can instead approximate functions by rational functions of the form , where 
 and 
 are polynomials. You have been asked by Approximate Calculation Machinery to solve this problem, so they can incorporate your solution into their approximate calculation software.
Given , 
, and the first 
 coefficients of the power series of 
, we wish to compute two polynomials 
 and 
 of degrees at most 
 and 
, respectively, such that the power series expansion of 
 has 
 as its first 
 coefficients, and 
 as its coefficient corresponding to the 
 term. In other words, we want to find 
 and 
 such that
where  contains terms with powers of 
 higher than 
. From this, 
 can be approximated by 
.
Background Definitions
A polynomial  of degree 
 can be written as 
, where 
's are integers in this problem.
A power series expansion of  about 
 can be written as 
, where 
's are integers in this problem.
Input Specification
The input will consist of multiple cases. Each case will be specified on one line, in the form 
where  is the coefficient of 
 in the power series expansion of 
. You may assume that 
, 
, 
, and 
 are integers such that 
. The end of input will be indicated by a line containing 
, and no coefficients for 
. You may assume that there is a unique solution for the given input.
Output Specification
For each test case, print two lines of output. Print the polynomial  on the first line, and then 
 on the second line. The polynomial 
 should be printed as a list of pairs 
(pi,i) arranged in ascending order in , such that 
 is a non-zero coefficient for the term 
. Each non-zero coefficient 
 should be printed as 
, where 
 and 
 is the coefficient expressed in lowest terms. In addition, if 
 then print only 
 (and omit 
). If 
, print a line containing only 
(0,0). Separate the pairs in the list by one space. The polynomial  should be printed in the same manner. Insert a blank line between cases.
Sample Input
2 2 0 0 1 1
4 2 1 2 3 4 5 -2
1 1 2 3
1 4 -5 0 -2 1 -2
0 0
Sample Output
(0,0)
(1,1)
(-4/33,0) (-1/11,1) (-2/33,2) (-1/33,3)
(-4/33,0) (5/33,1)
(2/3,0)
(1/3,0)
(25/6,0)
(-5/6,0) (1/3,2) (-1/6,3)
Comments