Codeforces627A【数学·有意思】

题意:
求有多少对( a , b ),a+b=s,a^b=x.(正整数)
思路:
a+b=a^b+a&b*2;

#include <iostream>
#include <cstdio>
#include<vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef __int64 LL;

int main()
{
    LL s,x;
    scanf("%I64d%I64d",&s,&x);
    LL t=(s-x)/2;
    if(s<x||(s-x)%2||x&t)
    {
        puts("0");
        return 0;
    }
    LL ans=0;
    int cnt=0;
    bool flag=true;
    if(s==x)
        ans-=2;
    while(x)
    {
        if(x&1)
            cnt++;
        x>>=1;
    }
    ans+=(1LL<<cnt);
    printf("%I64d\n",ans);
    return 0;
}
posted @ 2016-08-08 00:51  see_you_later  阅读(154)  评论(0编辑  收藏  举报