#include<iostream>
#include<vector>
using namespace std;
int jed(int n){
int odp = 0;
while(n>0){
odp+=(n%2);
n/=2;
}
return odp;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin>>n;
int x = 1;
while(n>0){
n-=jed(x);
++x;
}
--x;
vector<int>tab;
while(n<0){
if(n+jed(x)>0){
tab.push_back(x);
}
else{
n+=jed(x);
}
--x;
}
while(x>0){
tab.push_back(x);
--x;
}
cout<<tab.size()<<endl;
for(int i = 0;i<tab.size();++i){
cout<<tab[i]<<" ";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include<iostream> #include<vector> using namespace std; int jed(int n){ int odp = 0; while(n>0){ odp+=(n%2); n/=2; } return odp; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; int x = 1; while(n>0){ n-=jed(x); ++x; } --x; vector<int>tab; while(n<0){ if(n+jed(x)>0){ tab.push_back(x); } else{ n+=jed(x); } --x; } while(x>0){ tab.push_back(x); --x; } cout<<tab.size()<<endl; for(int i = 0;i<tab.size();++i){ cout<<tab[i]<<" "; } } |
English