0113. Roots of a Polynomial

Input file name: roots.in
Output file name: roots.out
Time limit: 5 s
Memory limit: 64 megabytes

Your task is to find real roots of a given non-zero polynomial.

Input file

The first line of the input file contains an integer number N (1 ≤ N ≤ 10) – degree of the polynomial. The next line contains N+1 integer numbers an an-1a0 (the polynomial is anxn+an-1xn-1+…+a1x+a0). They do not exceed 106 by an absolute value. The last line of the input contains a single integer D (1 ≤ D ≤ 1000) – the required number of digits after decimal point in output. It is guaranteed that all roots of the polynomial are simple.

Output file

Output the real roots with D digits after decimal point in ascending order. Standard rounding rules apply. That is, if the exact D+1-th digit after decimal point is 4 or smaller, the D-th digit in output is rounded downards; otherwise upwards.

Examples:

roots.inroots.out
1 -1 1 11.0


Source: Petrozavodsk Summer 2003. Primary Contest, Sunday, August 24
Author: Andrew Lopatin, Nick Durov

Discuss       Submit a solution



Printable version