提交时间:2026-10-28 13:57:45
运行 ID: 43252
#include <bits/stdc++.h> #define int long long using namespace std; int t,n,x,cnt,ans; signed main(){ // freopen("xor.in","r",stdin); // freopen("xor.out","w",stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>t; while(t--){ cin>>n>>x,ans=((x>>1)<<1),cnt=__popcount(x); if(n==1){ cout<<x<<"\n"; continue; } if(x&1){ --cnt; if(n&1){ ans+=n; if(cnt&1) --cnt; ans-=cnt; } else{ if(cnt==0) ans+=2; ans+=n-1; if(cnt&1) --cnt; else cnt-=2; ans-=cnt; } } else{ if(n&1){ ans+=n-1; if(cnt&1) --cnt; else cnt-=2; ans-=cnt; } else{ ans+=n; if(cnt&1) --cnt; ans-=cnt; } } cout<<ans<<"\n"; } return 0; }