Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define ld long double
- #define f first
- #define s second
- using namespace std;
- const ll inf = (1ll << 62);
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ll t;
- cin >> t;
- while(t--) {
- ll n, x;
- cin >> n >> x;
- ll ma = n, mi = inf;
- ll mask = 0;
- for(ll i = 0; i < 61; i++) {
- if(!((n >> i) & 1)) {
- if((x >> i) & 1) {
- mi = -1;
- break;
- }
- } else {
- ll now = n + (1ll << i) - (n & mask);
- if((x >> i) & 1) {
- mi = min(mi, now);
- } else {
- ma = max(ma, now);
- }
- }
- mask += (1ll << i);
- }
- if(ma < mi) cout << ma << '\n';
- else cout << "-1\n";
- }
- }
Add Comment
Please, Sign In to add comment