Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
43274 项奕琳 初二 【J】T2 C++ 解答错误 90 234 MS 248 KB 614 2026-10-28 14:17:10

Tests(9/10):


#include <bits/stdc++.h> using namespace std; #define int long long int t,n,x,k,cnt,ans; signed main(){ cin >> t; while (t--){ cin >> n >> x; if (n==1&&x==0){ cout << -1 << endl; continue; } if (x==1&&n%2==0){ cout << n+3 << endl; continue; } k=1,cnt=0,ans=0; while (x>0){ if (x%2==1){ ans += k; cnt ++; } x /= 2; k*=2; } if (cnt < n){ ans+=n-cnt; if ((n-cnt)%2==1){ ans++; if (cnt<=1) ans+=2; } } cout << ans << endl; } return 0; }


测评信息: