题目链接
统计一下n的二进制为1的位数,然后不断自加判断即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1010;
int n;
int main(){
while(cin>>n&&n){
int cnt=0,temp=n;
while(n){
if(n&1){
cnt++;
}
n>>=1;
}
while(1){
int sum=0;
int a=++temp;
while(a){
if(a&1){
sum++;
}
a>>=1;
}
if(sum==cnt){
cout<<temp<<endl;
break;
}
}
}
}