Problem Description
Input
Output
Example Input
2 3 0 1 1 0
Example Output
2 1 0
Hint
对于第二组样例:1是符合条件的x。
对于第三组样例:没有符合条件的
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int fun(int *a,int n)
{
int count=0;
while(n)
{
a[count++]=n%2;//记录每位数;
n/=2;
}
return count;//返回一共有有多少位;
}
int main()
{
int a,b;
int l,l1;
int a1[50],b1[50];//记录每个数换成二进制的逆序数;
int flag;
while(cin>>a>>b)
{
flag=0;
int sum=0;
int sum1=0;
memset(a1,0,sizeof(a1));
memset(b1,0,sizeof(b1));
l=fun(a1,a);
l1=fun(b1,b);
if(l>l1)//数大;
flag=1;
for(int i=0;i<l1;i++)
{
if(a1[i]==1&&b1[i]==0)//不符合条件则退出循环;
{
flag=1;
break ;
}
if(a1[i]==1&&b1[i]==1)//只要符合规律则成立;
sum++;
}
if(flag)
cout<<"0\n";
else
cout<<pow(2,sum)<<endl;//求2的sum次;
}
return 0;
}