CF-1011-C. Serval and The Formula · znzryb
## 思路讲解
$(x+k) + (y+k) = (x+k)\oplus (y+k) $ 等价于 $ (x+k)\&(y+k)=0$,其实就是不允许$x+k$和 $y+k$ 这位都是 $1$ 的情况。

然后呢,这种题虽然主要的思想是按位分析,但是还是需要构造的,而且不要试图构造一些不特殊的,而是构造一些特殊的(如上所示)。
## AC代码
[https://codeforces.com/contest/2085/submission/318796295](https://codeforces.com/contest/2085/submission/318796295)
::: 源代码
```cpp
// Problem: C. Serval and The Formula
// Contest: Codeforces - Codeforces Round 1011 (Div. 2)
// URL: https://codeforces.com/contest/2085/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int) a.size())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define getFro(vec) (vec.empty()?0:vec.front())
#define getBac(vec) (vec.empty()?0:vec.front())
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define DEBUG(variable) \
do { \
std::cerr << #variable << ":"; \
for (const auto& elem : variable) { \
std::cerr << elem << " "; \
} \
std::cerr << "\n"; \
} while (0)
#define uniVec(var) \
do { \
sort(var.begin(),var.end());\
var.resize(unique(var.begin(),var.end())-var.begin());\
} while (0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
typedef pair<DB,DB> pdd;
typedef pair<ll,bool> plb;
constexpr ll MAXN=static_cast<ll>(1e6)+10,INF=static_cast<ll>(1e18)+3;
constexpr ll mod=static_cast<ll>(1e9)+7;
constexpr double eps=1e-8;
ll N,M,K,T,A[MAXN];
ll X,Y;
ll bitX[35],bitY[35];
ll pow2[40];
inline void solve(){
cin>>X>>Y;
if(X==Y){
cout<<-1<<"\n";
return;
}
ll needPow=ceil(log2(max(X,Y)));
ll ans=pow2[needPow]-max(X,Y);
#ifdef LOCAL
cerr<<((X+ans)&(Y+ans))<<"\n";
#endif
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
pow2[0]=1;
FOR(i,1,35){
pow2[i]=pow2[i-1]*2;
}
while(T--){
solve();
}
// solve();
return 0;
}
/*
AC
https://codeforces.com/contest/2085/submission/318796295
*/
```
:::
## 心路历程(WA,TLE,MLE……)
之前陷入了错误思路中,认为是要按位分析,然后通过给每位+1避免出现11现象,其实这是很难的,因为进位会互相影响。