标签:
# include<iostream> # include<cstdio> # include<cmath> # include<string> # include<vector> # include<list> # include<set> # include<map> # include<queue> # include<cstring> # include<algorithm> using namespace std; # define LL long long # define REP(i,s,n) for(int i=s;i<n;++i) # define CL(a,b) memset(a,b,sizeof(a)) # define CLL(a,b,n) fill(a,a+n,b) const double inf=1e30; const int INF=1<<30; const int N=1000; unsigned long long n,k; const unsigned long long a=0xffffffffffffffff; unsigned long long ans; void dfs(unsigned x) { if(x<=0) return ; int t=x; int base=0; while(t){ t/=2; ++base; } unsigned long long p=1; int id; for(int cnt=0,i=0;i<64&&cnt<=base;++i){ id=i; if(n&(p<<i)){ ++cnt; if(cnt==base) ans|=(p<<i); } } dfs(x-(p<<(base-1))); } int main() { int T; scanf("%d",&T); while(T--) { cin>>n>>k; n=~n; ans=0; dfs(k); cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/20143605--pcx/p/5078363.html