## LCC '18 Contest 2 J4 - "Hard" Quadratics

View as PDF

Points: 7
Time limit: 3.0s
Java 8.0s
Python 8.0s
Memory limit: 64M

Author:
Problem types

One day, Mrs. Ma tells her whole class that there will be a very hard quadratic equations assignment given to the entire class to finish as an in-class assignment tomorrow. The whole class is freaking out but Larry is the most scared since he SUCKS at solving quadratics.

Luckily, Mrs. Ma has given the details of the assignment. She will give a list of quadratic equations in the form of $$ax^2+bx+c=0$$ with one coefficient ($$a$$, $$b$$, $$c$$) unknown and its two roots. Then the students will be asked to solve for the unknown coefficient.

Write a program that can solve the quadratics given and save Larry from failing the assignment!

#### Input Specification

The first line will contain the integer $$N\ (1 \le N \le 10^6)$$.

The next $$N$$ lines will contain the quadratic in the form of $$ax^2+bx+c=0\ (-10^3 \le a \le 10^3;\ -10^7 \le b \le 10^7;\ -10^{16} \le c \le 10^{16};\ a, b, c \neq 0)$$ and its two roots $$(-10^6 \le r_1, r_2 \le 10^6;\ r_1, r_2 \neq 0)$$.

If the quadratic has a double root, it is printed twice.

If $$a=1$$, $$b=1$$, or $$c=1$$, then the $$1$$ is not shown. See sample input 1 for an example.

#### Output Specification

Output the missing coefficient.

#### Sample Input 1

1
x^2+bx+1=0 1 1

#### Sample Output 1

-2

#### Sample Input 2

4
ax^2-12x+35=0 5 7
2x^2+6x+c=0 -2 -1
x^2+bx+6=0 -6 -1
3x^2+bx+69=0 1 23

#### Sample Output 2

1
4
7
-72