Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
43247 _Yuyuyu_ 【J】T2 C++ 通过 100 234 MS 256 KB 879 2026-10-28 13:57:30

Tests(10/10):


#include<bits/stdc++.h> using namespace std; #define int long long int t,n,x; void jc(int x){ if(x==0&&n==1){ cout<<-1<<endl; return; } if(x==0&&n%2){ cout<<n-2+5<<endl; return; } int ans=0,tx=x; while(tx){ if(tx&1)ans++; tx>>=1; } if(ans>n){ cout<<x<<endl; return; } if(ans==1){ if(n%2){ cout<<x+n-1<<endl; return; } if(x==1)cout<<3+n<<endl; else cout<<x+n<<endl; return; } else{ if((n-ans)%2){cout<<x+n-ans+1<<endl;} else cout<<x+n-ans<<endl; return; } cout<<-1<<endl; } signed main(){ cin>>t; while(t--){ cin>>n>>x; jc(x); } return 0; } /* 思路: 1:分奇偶 2:二进制分解 */


测评信息: