题目链接:
http://codeforces.com/contest/635/problem/C
题意:
给定两个数的和s及异或x,求两个数的可能情况。
分析:
我们有公式
这样对于与和异或的结果一位一位的来考虑即可。
注意:
- 题目特别强调Two positive integers a and b,所以在
s 与x 相等时,我们要减去0的情况。 - 差为奇数的情况很明显不存在ab。
- 按位判断的时候注意xx和tt都为1的情况也是不存在的。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define pr(x) cout << #x << ": " << x << " "
#define pl(x) cout << #x << ": " << x << endl;
#define sa(x) scanf("%d",&(x))
#define sal(x) scanf("%I64d",&(x))
#define mdzz cout<<"mdzz"<<endl;
const int maxn = 2e5 + 5, oo =0x3f3f3f3f;
typedef long long ll;
//a + b = a & b * 2 + a ^ b
int main (void)
{
ll s, x;sal(s);sal(x);
ll t = s - x;
if(t & 1) return puts("0"),0;
t >>= 1;
int tt = 1, xx = 1;
ll ans = 1;
ll tx = x;
while(t || x){
tt = t & 1;
xx = x & 1;
if(!tt && xx) ans <<= 1;
if(tt && xx) return puts("0"), 0;
t >>= 1;
x >>= 1;
}
if(s == tx) ans -= 2;
printf("%I64d", ans);
return 0;
}