Solving cubic equations 2
InterviewTime limit2sMemory limit512 MB
Find all real roots of a cubic with rational coefficients, printing them rounded to four decimals, using that at least one root is an integer.
- Level
Medium7 of 10
- Topics
- Math, Binary search, Implementation, Number theory
- Solved
- No attempts yet
Problem
Write a program that finds every real root of the cubic equation .
Every equation in the input has at least one integer root.
The absolute value of , , , and is at most , and is not zero. Every real root has absolute value at most . , , , and can carry up to 11 digits after the decimal point. Within one equation, two different roots differ by more than .
Input
The first line contains the number of test cases (). Each of the next lines contains the coefficients , , , and of one equation, separated by spaces.
Output
For each equation, print all of its real roots in ascending order on one line. Separate two roots with a single space and round each root to four digits after the decimal point. Print a multiple root only once. If a root rounds to zero, print 0.0000 and not -0.0000.