題目鏈接:
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;
}