955C - Sad powers in this problem a very strange behavior of compiler had happened and i didn't understand why ?? :|
In the above submission links you can see that first one is submitted in GNU C++14 and second one is submitted in GNU C++17 and third one submitted in GNU C++11. But unfortunately first one got WA and second one got AC. 3rd submission also got WA but same code. can anyone tell me why this happened ?
Thanks.
That's because of builtin sqrt() function you are using. Try writing your own sqrt() function & see that your code gets Accepted in C++11 , C++14 & C++17
why does this code work then? literally the same thing, just the variables changed.
That's "undefined" behaviour u know !!
sqrt() might give something slightly less than the actual square root (because of double precision) and converting it to long long would truncate the double(making the answer wrong by 1). So, you should add something like 0.01 before converting to long long.
Thanks siddhant22 and SAKIB_ALAMIN . But this types of problems are horrible during contest, though those were offline submissions :3
43416957 43416933 Spot The Difference (HARD)