当 ,答案一定为
设答案为k, 设 即 ,
考虑拆位,设 表示 在二进制表示下的第 位,从大往小枚举
-
当 , 时 ,因为要使最小
-
当 , 时 ,且这时,直接break掉
-
当 , 时,因为要使
-
当 , 时
代码
#include <bits/stdc++.h>
using namespace std;
int main (){
int t;
cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
if(n>m) {
cout<<0<<endl;
continue;
}
m++;
int k=0;
for(int i=30;i>=0;i--){
if(((m&(1<<i))==0)&&((n&(1<<i))!=0)){
break;
}
if(((n&(1<<i))==0)&&((m&(1<<i))!=0)){
k+=1<<i;
}
}
cout<<k<<endl;
}
}