#include<bits/stdc++.h>
using namespace std;
int CountBits (int x){
int wyn=0;
while (x){
wyn+= x & 1;
x=x>>1;
}
return wyn;
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int k;
cin>>k;
int o=0;
int e=0;
while (o<k){
e++;
o+=CountBits(e);
}
int a=e;
int akt=0;
int pol=0;
vector<int> wyn;
while(a){
if (akt<o-k){ //Jeśli istnieje nadmiar
pol=CountBits(a);
if (pol<=o-k){
akt+=pol;
// cout<<"BEZ "<<a<<endl;
}
else{
wyn.push_back(a);
}
} else {
wyn.push_back(a);
}
a--;
}
cout<<wyn.size()<<"\n";
for (auto el:wyn){
cout<<el<<" ";
}
return 0;
}
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 45 46 47 48 49 50 51 52 | #include<bits/stdc++.h> using namespace std; int CountBits (int x){ int wyn=0; while (x){ wyn+= x & 1; x=x>>1; } return wyn; } int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int k; cin>>k; int o=0; int e=0; while (o<k){ e++; o+=CountBits(e); } int a=e; int akt=0; int pol=0; vector<int> wyn; while(a){ if (akt<o-k){ //Jeśli istnieje nadmiar pol=CountBits(a); if (pol<=o-k){ akt+=pol; // cout<<"BEZ "<<a<<endl; } else{ wyn.push_back(a); } } else { wyn.push_back(a); } a--; } cout<<wyn.size()<<"\n"; for (auto el:wyn){ cout<<el<<" "; } return 0; } |
English