REBOUND - The return of the Cake

no tags 

It is well known that, in byteland, when you throw a cake, the angle of reflexion is not the angle of incidence. Measured from the ground, the angle is the double, in byteland!


You stand at point A(0, z), and you want to throw a cake in Leo's face. Leo stands at B(x, y) and is a very dangerous man, so you decide to use the ground in order to make your cake rebound.

Your shot is precise only if you can use an integer value t in the intervall [0, x], in order to reflect on C(t, 0). Sometimes it's possible, sometimes not!


The input begins with the number T of test cases in a single line. In each of the next T lines there are three integers x, y and z, explaining the locations : you A(0, z), Leo B(x, y).


For each test case, find and print the only integer t such 0 <= t <= x, that allow this perfect shot. If it's not possible, output "Not this time.".


5 4 1
6 5 2
7 3 1

Not this time.

Comment : the last case is the one illustrated above.


1 < T < 100 000
0 < x < 1 000 000 000
0 < y < 1 000 000 000
0 < z < 1 000 000 000

Edit(2017-02-11) : New time limit (after compiler changes).

hide comments
sonuverma: 2018-02-02 16:29:02

Nice Problem :-)

cs_abhi2000: 2017-01-11 08:08:12

@Mayank Pratap Thank u for giving hint...

alok singh: 2015-08-24 09:50:10

clang rocks... green in one go @shantanu tripathi :p

[Mayank Pratap]: 2015-06-19 10:41:44

Try to avoid overflow... Nice problem on algebra and trigo ...

Naman Goyal: 2015-05-20 04:28:33

This is weird, I didn't know that C++ (4.3.2) sqrt function has some problems with unsigned long long int. Costed me like infinite WA's . Finally just removing unsigned worked and got AC.

Harshit: 2015-03-28 19:11:39

any typical test case??

(Francky) => No other test case is provided.

Last edit: 2015-03-29 18:30:07
pika_pika: 2013-07-16 20:03:45

easy but the damned '.' cause so many WA's
.was printing "Not this time" instead of "Not this time." :(

sam: 2013-02-17 14:32:11

please give me some more tricky test cases
--ans--> No other cases are provided, you have to build them on your own. Good luck.

Last edit: 2013-02-17 15:32:47
sam: 2013-02-15 17:49:12

what is output for x=0,y=0,z=0..........................
please help admin
Ans(Tjandra): No case like that, read the constraints carefully..

Last edit: 2013-02-15 21:08:37

Added by:Francky
Time limit:0.75s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem