1790E: Vlad and a pair of Numbers (Doubt)

Revision en2, by ProveMeRight, 2023-06-11 08:51:12

209248600

...
int a = x;
int b = 0;

for(int i= 29;i>=0;i--)
    {
        if((x & (1 << i)) > 0)
        {
            continue;
        }

        if((2*x - a - b) >= (2 << i))
        {
            // bug(a,b);
            a += (1 << i);
            b += (1 << i);
        }
    }

When I am making the start from i= 30 or more, it makes a negative. Why?

Note: I defined int as long long. Still, It's doing the same.

Can anyone please explain?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English ProveMeRight 2023-06-11 08:51:12 15
en1 English ProveMeRight 2023-06-11 08:49:21 538 Initial revision (published)