题解:P16138 位的方程(popcount)
题目大意
给定一个数
题目思路
设
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long//范围较大
int gs(int x){//x在二进制下1的个数
int sum=0;
while(x!=0){
int tmp=x%2;
if(tmp==1){
sum++;
}
x/=2;
}
return sum;
}
int t;
signed main(){
cin>>t;
while(t--){
bool p=0;//看是否有k满足
int a;
cin>>a;
for(int k=1;k<=64;k++){
int tmp1=a*k;
if(gs(tmp1)==k){
cout<<a*k<<endl;//如果满足直接输出并标记p=1,结束循环
p=1;
break;
}
}
if(p==0){//不满足输出-1
cout<<"-1"<<endl;
}
}
return 0;
}