您的位置:首页 > 其它

CodeForces 635C XOR Equation 数学 公式

2016-08-15 20:47 363 查看
#include<stdio.h>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
#include<functional>
#include<vector>
#include<iomanip>
#include<math.h>
#include<iostream>
#include<sstream>
#include<set>
#include<climits>
#include<map>
#include<bitset>
using namespace std;
int main()
{
cin.sync_with_stdio(false);
long long s,x,Ans=0;
cin>>s>>x;
//a + b = (a Xor b) + (a & b) * 2  ;
//a + b = s ; a Xor b = x ;
//s - x = (a & b) * 2;
if ((s-x>=0)&&(s-x)%2==0)
{
long long Andsum = (s - x) >> 1;
int cnt = 0;
bool flag = true;
if(s==x) Ans = -2;
while(x)
{
if(x&1)
{
cnt++;
if(Andsum&1)
flag = false;
}
if (!flag)
break;
x>>=1;
Andsum>>=1;
}
if (!flag)
Ans=0;
else Ans+=(1LL<<cnt);
}
cout<<Ans;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: