Example challenge

The input of the program consists of a certain number of datasets. Each dataset consists of three lines. The first line contains a positive integer n<10, representing the degree of a polynomial. The second line contains a list of n+1 coefficients a_0, a_1, …, a_{n} of the polynomial

f(x) = a_nx^n + a_{n-1}x^{n-1} + ... + a_1x + a_0

The last line contains two integers c and d satisfying the property f(c) f(d) < 0. Your task is to find an arbitrary root (zero) x_0 of polynomial f with precision \varepsilon = 0.001, i.e., print any point x_0 satisfying the condition f(x_0)| \le \varepsilon.

For instance, the polynomial x^5 - x – 1 has exactly one real root in the vicinity of point 1.167236. Interestingly enough, this point cannot be represented precisely through rational numbers of their roots of any order.

Example input:

3
4 3 2 1
-2 -1
2
-2 0 1
1 2
5
-1 -1 0 0 0 1
1 2

Example output

-1.650635
1.414062
1.167236

Sample solutions


function foo(items) { var x = "All this is syntax highlighted"; return x; }