提交时间:2026-10-28 15:06:12
运行 ID: 43299
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans; void f(ll n,ll x){ ans=0; ll c=__builtin_popcount(x); if(n<=c){ cout<<x; return; } if((n-c)%2==0){ ans=x+(n-c); }else{ if(x==1)ans=n+3; if(x>1)ans=x+(n-c)+1; else{ if(n==1){ cout<<-1; return; } else ans=n+3; } } cout<<ans<<endl; } int main(){ ll t;cin>>t; while(t--){ ll n,x; cin>>n>>x; f(n,x); } return 0; }