eolymp
bolt
Try our new interface for solving problems
Problems

Solutions of Cubic Equation

Solutions of Cubic Equation

Hannah asked you to determine all distinct real solutions of a cubic equation in the following form: \textbf{Ax^3 + Bx^2 + Cx + D = 0} The task is quite complicated especially if one solution is irrational. Before you complained, Hannah told you that she'll only give cubic equations with at least one integer solution. Your task then is to find all distinct real solutions of the cubic equation given the coefficients \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D} where \textbf{A }is not \textbf{0}. The range of values of \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D} is \textbf{-2000000} to \textbf{2000000}. The range of values of \textbf{x} is \textbf{-1000000} to \textbf{1000000}. \InputFile The input starts with an integer \textbf{N} (where \textbf{0} < \textbf{N} < \textbf{100}). It is then followed by \textbf{N} input lines. Each input line consists of four numbers \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D}, not necessarily integers. \textbf{A} is never \textbf{0}. \OutputFile For each input line, print all distinct real solutions of the cubic equation in one line, sorted in increasing order. Each real solution must be rounded off to the nearest ten thousandth and must be printed with exactly four digits after the decimal point. Two or more distinct real solutions must be separated by exactly one space.
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
3
1.5 -5 2 -1.5
2 -7 7 -2
2 0 0 0
Output example #1
3.0000
0.5000 1.0000 2.0000
0.0000
Source ACM ICM Philippines Multi-Provincial Programming Contest 2013