Welcome to ZOJ
Select Problem
ZOJ Problem Set - 2410
Partial Fraction Decomposition

Time Limit: 2 Seconds      Memory Limit: 65536 KB

It is easy to obtain (6x2-5x-5)/(x3-2x2-x+2) from 1/(x+1) + 2/(x-1) + 3/(x-2). But how about the other way around?

Given a rational function in the form (a2x2+a1x+a0)/(x3+b2x2+b1x+b0) where ai and bi are integers for i = 0, 1, 2. If the denominator factors as (x-r1)(x-r2)(x-r3) where ri's are distinct integers, then these will be the denominators of the partial fraction decomposition. We are looking for a decomposition of the rational function such that

A1/(x-r1) + A2/(x-r2) + A3/(x-r3) = (a2x2+a1x+a0)/(x3+b2x2+b1x+b0)


The input consists of several test cases, each occupying a line with 6 integers in the format:
a0 a1 a2 b0 b1 b2
A case with a0=a1=a2=0 signals the end of input and must not be processed.


For each test case, print in one line the 6 numbers in the format:
r1 r2 r3 A1 A2 A3
Note: It is guaranteed that the decomposition exists for each case, because I obtained the input from output ^_^. It is also guaranteed that ri's are distinct integers and you must output them in increasing order. However, it is NOT guaranteed that Ai's are integers, and you must output them accurate up to 2 decimal places.

Sample Input

-5 -5 6 2 -1 -2
-5 -3 5 2 -1 -2
0 0 0 1 2 3

Sample Output
-1 1 2 1.00 2.00 3.00
-1 1 2 0.50 1.50 3.00

Author: CHEN, Yue
Source: Zhejiang University Local Contest 2005
Submit    Status