O - XOR

You are given non-negative integers x, k. Please compute how many non-negative y satisfy y + (x xor y) = x + k. Here + is the usual addition and xor means bitwise exclusive-or. If there are infinitely many such y, please output -1.

Input

First line contains two integers x,k. (0 ≤ x, k ≤ 109)

Output

Output one line containing the answer.

Sample Input

3 24

Sample Output

4
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,k;int num=0;
	cin>>x>>k;
	if((k%2)!=0||(k/2&x)){
		cout<<0<<endl;
		return 0;
	}
	while(x){
		if(x&1) num++;
		x>>=1;
		
	}
	cout<<pow(2,num)<<endl;
	return 0;
}

这道题目异常简单,看代码就能明白。

但是一开始我用了pow函数,原形是float,有误差

所以应该直接移位。

不知道原形的不要随便用。

猜你喜欢

转载自blog.csdn.net/qq_42865713/article/details/87070500
xor
o