While solving problem B in Codeforces Round 976 when I was calculating my answer I was using the square root function to calculate
WA
but it was giving WA on test case on k = 854258779689358055
instead when I wrote the same code in C++ and submitted it , it gave AC....Could anyone tellme why that happened...
Help please...
Change first line of the while loop:-
mid=L+(R-L)/2
You are experiencing the error because for worst case R=5e18 and L=5e18-1 So L+R=1e19-1 which exceeds the max value of long(9e18) and hence gives a faulty value(possibly -9e18 or something).
Hope this helped you (-:
It is still giving WA
You should always use sqrtl instead of sqrt because of precision issues.
Here is the equivalent
static long sqrtl(long x) {
Hope this helps
Thanks a lot ......