题目
链接:https://ac.nowcoder.com/acm/contest/11258/I 来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld
题目描述
xay loves or. He gives you x and s, you need to calculate how many positive integer y satisfy xor?y=sx \operatorname{or} y=sxory=s .
输入描述:
The first line contains two positive integers x and s .
It's guaranteed that 1≤x,s<2311\le x,s<2^{31}1≤x,s<231 .
输出描述:
Print the number of y satisfy xor?y=sx \operatorname{or} y=sxory=s .
示例1
输入
[复制](javascript:void(0)😉
2 5
输出
[复制](javascript:void(0)😉
0
解释与代码
给出x和s?,问存在多少个y使得x|y=s
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <limits.h>
#include <assert.h>
#include <functional>
#include <numeric>
#include <ctime>
#define pb push_back
#define ppb pop_back
#define lbnd lower_bound
#define ubnd upper_bound
#define endl '\n'
#define mll map<ll,ll>
#define msl map<string,ll>
#define mls map<ll, string>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) for(auto& a : x)
#define pll pair<ll,ll>
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define vs vector<string>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define DEBUG cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x) cerr << #x << " is " << x << endl;
#define ini(a) memset(a,0,sizeof(a))
#define ini2(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define case ll T;cin>>T;for(ll Q=1;Q<=T;Q++)
#define lowbit(x) x&(-x)
#define pr printf
#define sc scanf
#define _ 0
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DBG(x) \
(void)(cout << "L" << __LINE__ \
<< ": " << #x << " = " << (x) << '\n')
#define TIE \
cin.tie(0);cout.tie(0);\
ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e7*2+10;
const ll N = 5;
typedef struct LNode{
int coef,index;
struct LNode *next;
}LNode,*LinkList;
struct SegmentTree{
int l, r;
int dat;
}t[N*4];
bool cmp(int a,int b){
return a>b;
}
void solve(){
ll x, s, ans = 1, xx, ss;
cin>>x>>s;
xx = x,ss = s;
ll a, b, cnt = 0;
if (x>s) {
cout<<0<<endl;
return ;
} else if (x<s) {
for (; x; x>>=1,s>>=1) {
if ((x&1) && (s&1)==0) {
cout<<0<<endl;
return ;
} else if ((x&1) && (s&1)) {
ans*=2;
} else if ((x&1)==0 && (s&1)) {
cnt = 1;
}
}
} else {
for (; x; x>>=1) {
if (x&1) {
ans*=2;
}
}
}
if ((0|xx)==ss) {
ans--;
}
cout<<ans<<endl;
}
int main()
{
solve();
}
|