Sujay_27's blog

By Sujay_27, history, 12 months ago, In English

Hello folks, Need some help in debugging.. The question is on the right : Ques This is the code I submitted : Code I don't know why I'm getting signed integer overflow, inspite of having all the variables as long long. Can someone enlighten me on what I'm missing. [contest:918][problem:1915C]

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

| Write comment?
»
12 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Sum can be 1e14 which would lead to overflow you can set a upperlimit of 1e9

»
12 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

The maximum value that a long long variable can have is $$$2^{63} - 1$$$. In your code sum can be equal to $$$2 \cdot 10^{14}$$$ in some test cases and thus mid * mid may get bigger than the long long limit.

»
12 months ago, # |
  Vote: I like it 0 Vote: I do not like it

In worst case, the sum can be 2*10^14 then the mid will be 10^14. mid * mid will be 10^28. long long can hold at most 10^18.