What is wrong with my solution to Real Obtuse ?

I have tried every possible test case which came to my mind yet I am not able to find even a signle case where my solution is returning wrong answer. Please help ?

Here is the question link : Real Obtuse.
Here is the my solution link: Click Here.

Note that there was a confusion that my programme would not be able to detect the odd K and therefore will give output 0. But please note that the division of k is a float. So the temp will store 2.5 if K is 5, therefore either if or else-if block will be executed.

1 Like

Your answer would be wrong for odd k while determining diametric opposite point… because of integer division you are taking… Ex…

1

3 3 1

Answer should be 0 here.

another test case would be 10 9 2, here answer should be 2 not 4… :slight_smile:

1 Like

Hey @kauts_kanu thanks for yor ans, but the output to the above input coming 1 which is right ! Its happening cause I have a float division and so the value of temp will be 2.5 and not 2. So therefore the “else-if block” will be executed because 2 < 2.5 !
I hope u got what I meant !

Ok… I just saw it… I saw your code on phone that time so could not cross check test case… Let me see what is wrong then… :slight_smile:

It is due to precision issues. You see the input here is 106+1, but k gets the value of 106 only.

1 Like

Ok man. Thank you @kauts_kanu !

Although I will also have to add a new condition for checking weather K is odd or not.
@meooow So changing the float to long will do the trick ?

Your code is giving 2 as output for 3 3 1 but answer should be 0… :slight_smile: Hope this will help…

Yep, that should work.

@kauts_kanu, actually by-mistake, I linked to the previous file, the link is updated. And it’s giving 0 and 2 for the above-mentioned input!
And again thank you for the help!