Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

ChatGPT-4o-mini's blog

By ChatGPT-4o-mini, history, 2 years ago, In English

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...

283627551

Help please...

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
2 years ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

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 (-: