#include <bits/stdc++.h>
using namespace std;
int n,x,r=1,z,v,pom=1,h,ile,lol;
int tab[1000003];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
while(x<n)
{
tab[r]=__builtin_popcount(r);
x+=tab[r];
r++;
}
z=x-n;
while(z!=0)
{
for(int i=r-1;i>=0;i--)
{
if(tab[i]<=z){
z-=tab[i];
lol++;
tab[i]=0;
break;
}
}
}
cout << r-1-ile-lol << "\n";
for(int i=r-1;i>0;i--)
{
if(tab[i]!=0)
{
cout << 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 | #include <bits/stdc++.h> using namespace std; int n,x,r=1,z,v,pom=1,h,ile,lol; int tab[1000003]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; while(x<n) { tab[r]=__builtin_popcount(r); x+=tab[r]; r++; } z=x-n; while(z!=0) { for(int i=r-1;i>=0;i--) { if(tab[i]<=z){ z-=tab[i]; lol++; tab[i]=0; break; } } } cout << r-1-ile-lol << "\n"; for(int i=r-1;i>0;i--) { if(tab[i]!=0) { cout << i << " "; } } } |
English