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

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

Auto comment: topic has been updated by Sujay_27 (previous revision, new revision, compare).

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

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

instead of binary search,why arent you using sqrt its much simpler code

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

    yea I figured that, but wanted to try with binary search

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

it works if you use unsigned long long instead of signed long long (long long)

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

    Oh ok

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

    nah mate, unsigned long long only goes up to about 1.84*10^19, which is still nowhere near 10^28.