Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int a, b;
- cin>>a>>b;
- if(a == b)
- {
- cout<<0<<"\n";
- continue;
- }
- if(a<b) swap(a, b);
- int bit = -1;
- for(int i=29; i>=0; i--)
- {
- int x = (1<<i);
- if((a&x) != (b&x))
- {
- bit = i;
- break;
- }
- }
- int ans = 0;
- for(int i=bit-1; i>=0; i--)
- {
- int x = (1<<i);
- if((a&x)>0 && (b&x)==0)
- ans += x;
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment