LKP '18 Contest 1 P3 - Polynomial Madness

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.6s
Python 1.8s
Memory limit: 64M

Authors:
Problem types

Konajya is learning how to factor polynomials. Her homework assignment consists of N polynomials which she must factor. The i-th polynomial has degree Di. Each polynomial is described by a sequence of Di+1 integers which are the coefficients of the polynomial (i.e. x2+3x+9 would be given in the format of 1 3 9). Luckily, you know that each polynomial only has real integer roots. Because she is too lazy to factor them by herself, she decided to give this problem to you, so you can do it for her!

Constraints

1N10000
2Di7
All roots are integers whose absolute value is less than or equal to 150.
The polynomial evaluated at x where 150x150 will always yield an absolute value less than 2631.

Subtask 1 [5%]

N20

Subtask 2 [10%]

N300

Subtask 3 [25%]

N2000

Subtask 4 [60%]

No additional constraints.

Input Specification

On the first line, there is one integer, N, the number of polynomials to follow.
The next N lines contain an integer D representing the degree of the polynomial, followed by D+1 space-separated integers, the coefficients of the polynomial starting from the highest degree to the lowest degree.

Output Specification

Output a total of N lines.
Line i should contain the roots of the i-th polynomial in the input in increasing order. It is guaranteed that the polynomial has Di integer roots. You are to print the multiple roots.

Sample Input

Copy
3
2 2 -6 4
2 1 6 9
2 1 0 -9

Sample Output

Copy
1 2
-3 -3
-3 3

Comments

There are no comments at the moment.