Root Solver

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type

Write a program that solves for the root of a univariate polynomial with a maximum degree of 100.

Input Specification

Line 1 of the input contains an integer T (1 \le T \le 101), indicating the number of terms in the polynomial.
The next T lines each contain a real number coefficient and a whole number exponent from 0 to 100 inclusive.
Terms will always be collected (i.e. exponents will not be repeated) and arranged in descending powers.

Output Specification

In order from lowest value to highest value, every real solution for when the polynomial is equal to zero.
Your answer must be accurate within \pm 10^{-5} in absolute and relative error.
If there are no real solutions to the equation, output NO REAL ROOTS.

Note: Coefficients and answers can have up to 18 digits, and will fit inside a long double.

Sample Input 1

2
2 3
-54 0

Sample Output 1

3

Explanation for Sample Output 1

This asks for the solution(s) of x for the equation 2x^3-54=0.

Sample Input 2

3
3 2
4 1
-20 0

Sample Output 2

-3.33333
2

Explanation for Sample Output 2

This asks for the solution(s) of x for the equation 3x^2+4x-20=0.


Comments

There are no comments at the moment.