#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int maxx = 1e5;
int last[maxx];
set<int>secik;
int main()
{
int n; cin>>n;
int licznik = 0;
int ost;
for(int i=1; 1>0; i++)
{
if(licznik + __builtin_popcount(i) <= n)
{
secik.insert(i);
licznik += __builtin_popcount(i);
last[__builtin_popcount(i)] = i;
ost = i;
}
else break;
}
if(licznik == n)
{
cout<<secik.size()<<endl;
auto it = secik.begin();
vector<int>wyn; wyn.clear();
for(; it != secik.end(); it++)
{
int x = *it;
wyn.push_back(x);
}
reverse(wyn.begin(),wyn.end());
for(int i=0; wyn.size()>i; i++)
{
cout<<wyn[i]<<" ";
}
return 0;
}
int x = n - licznik;
int y = __builtin_popcount(ost+1);
secik.erase(last[y-x]);
secik.insert(ost+1);
cout<<secik.size()<<endl;
auto it = secik.begin();
vector<int>wyn; wyn.clear();
for(; it != secik.end(); it++)
{
int x = *it;
wyn.push_back(x);
}
reverse(wyn.begin(),wyn.end());
for(int i=0; wyn.size()>i; i++)
{
cout<<wyn[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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; const int maxx = 1e5; int last[maxx]; set<int>secik; int main() { int n; cin>>n; int licznik = 0; int ost; for(int i=1; 1>0; i++) { if(licznik + __builtin_popcount(i) <= n) { secik.insert(i); licznik += __builtin_popcount(i); last[__builtin_popcount(i)] = i; ost = i; } else break; } if(licznik == n) { cout<<secik.size()<<endl; auto it = secik.begin(); vector<int>wyn; wyn.clear(); for(; it != secik.end(); it++) { int x = *it; wyn.push_back(x); } reverse(wyn.begin(),wyn.end()); for(int i=0; wyn.size()>i; i++) { cout<<wyn[i]<<" "; } return 0; } int x = n - licznik; int y = __builtin_popcount(ost+1); secik.erase(last[y-x]); secik.insert(ost+1); cout<<secik.size()<<endl; auto it = secik.begin(); vector<int>wyn; wyn.clear(); for(; it != secik.end(); it++) { int x = *it; wyn.push_back(x); } reverse(wyn.begin(),wyn.end()); for(int i=0; wyn.size()>i; i++) { cout<<wyn[i]<<" "; } } |
English