Want to solve this problem? Login now to get access to solve the problems
1. Do not print anything, just return the roots of the quadratic equation or -1 if no roots exist. 2. If the equation has repeated roots, return the roots twice. 3. If there are imaginary roots, return -1 twice. 4. If the root is not an integer, return the greatest integer value less than the root. 5. a,b,c are integers
The first line of input contains an integer ‘T’ denoting the number of test cases. Each test case consists of three space-separated integers a,b,c which denotes the coefficients int the polynomial: ax^2+bx+c=0.
For each test case, return a pair of integers, denoting the roots of the quadratic equation. If the roots are imaginary, return a pair of -1. If there are repeated roots, return a pair with the same integer twice.
1 <= T <= 10^5 -10^3 <= a,c <= 10^3 -10^4 <= b <= 10^4 a≠0 Where ‘T’ is the total number of test cases, ‘a’,’b’,’c’ denotes the coefficients in the quadratic equation: ax^2+bx+c Time limit: 1 second
3 1 -5 6 1 -2 -2 1 0 1
2 3 -1 2 -1 -1
As depicted by the first line, there are total of three test cases. For the first test case, we can see that the quadratic equation is x^2-5x+6=0. Solving the equation we get (x-2)(x-3)=0 which gives us the factors of the given equation, hence the roots are x=2 and x=3. Therefore we return 2 and 3 For the second test case, we can see that the quadratic equation is x^2-2x-2=0. Solving we get (x-1+√3)(x+1-√3)=0 which gives us the factors of the given equation, hence the roots are x= (1-√3)≈ -0.732051 and x=(1+√3)≈2.732051. Since the roots are not integers, we return the greatest integer less than the roots i.e 0 and 2 respectively. For the third test case, we can see that the quadratic equation is x^2+1=0. Trying to solve it we get x^2=-1. We know that it is impossible to have the square of a real number equal to a negative number, so this quadratic equation has imaginary roots. Hence we return -1 twice.
2 3 -6 -18 1 -7 12
-2 3 3 4