ROOTCIPH - Decipher

Radar scanned the approaching enemy aircraft on the border. However due to some error part of the tranmitted data can't be deciphered. It was possible only to obtain the coefficients of the cubic polynomial, whose roots are the coordinates of the aircraft relative to the radar. Now you need to calculate the distance to the aircraft. Write the program to solve this task.


The first line contains T (1 <= T <= 1000) - number tests. The next T lines contain three integers a, b and c - coefficients of the polynomial x3 + ax2 + bx + c, whose roots are the coordinates (the absolute value of the coordinates do not exceed 108).


For each test print the square of the distance to the enemy aircraft.


-6 11 -6


hide comments
davidgalehouse: 2019-01-12 07:53:28

There are numbers in the input larger than the limit of a 64-bit signed integer. Scanf and cin react to overflowing input in different ways (look this up or experiment), which is why scanf solutions are succeeding and cin solutions are failing. I don't want to give too much away, but only the c coefficient overflows--this fact may help you create a 'workaround' once you figure out the solution (which isn't so easy IMO).

Last edit: 2019-01-12 08:32:55
dynamo214: 2018-08-16 19:03:14

Dont use any cin cout instead use printf scanf dont know why it is happening.

badal: 2018-01-25 09:28:14

Why using cin gives WA but scanf gives AC?

nikroc896: 2017-08-07 15:09:42

AC in one go :)

kr_abhinav: 2017-06-22 08:18:21

To all the guys wondering why they are getting WAs with cin/cout, it's because coordinates can be as large as 100000000, and so the constant term in polynomial can be as large as 10**24 . use string for c and get AC :D

sagnik_66: 2017-06-08 13:47:38

using cin to take inputs of a,b,c gives WA, but using scanf for those values works!

vineetpratik: 2017-03-30 20:54:35

haha AC using scanf/printf WA in cin/cout

starbot: 2017-03-13 15:46:41

too easy...basic maths...WA with cin/cout,AC with scanf/printf

nilabja16180: 2017-03-10 09:43:32

WA using cin,cout, AC using scanf, printf! :/ curious!

cake_is_a_lie: 2017-02-21 14:28:23

This is amazingly weird, but as somebody before stated, I got WA using cin/cout and AC using scanf/printf. The solution is amazingly simple and only uses integer arithmetic, so no idea why.

Added by:Spooky
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Resource:Advancement Spring 2010,, author: Alexey Shchepin