#include<bits/stdc++.h>
using namespace std;
int n;
int kon,sum[1000001];
vector<int>dowyp;
int pcpcnt(int a)
{
int ret=0;
while(a)
{
ret+=(a&1);
a>>=1;
}
return ret;
}
int main()
{
scanf("%d",&n);
for(int i=1;sum[i-1]<n;++i)
{
sum[i]=sum[i-1]+pcpcnt(i);
kon=i;
}
while(n)
{
while(sum[kon-1]>=n)
--kon;
dowyp.push_back(kon);
n-=pcpcnt(kon);
--kon;
}
printf("%lu\n",dowyp.size());
for(auto i:dowyp)
printf("%d ",i);
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 | #include<bits/stdc++.h> using namespace std; int n; int kon,sum[1000001]; vector<int>dowyp; int pcpcnt(int a) { int ret=0; while(a) { ret+=(a&1); a>>=1; } return ret; } int main() { scanf("%d",&n); for(int i=1;sum[i-1]<n;++i) { sum[i]=sum[i-1]+pcpcnt(i); kon=i; } while(n) { while(sum[kon-1]>=n) --kon; dowyp.push_back(kon); n-=pcpcnt(kon); --kon; } printf("%lu\n",dowyp.size()); for(auto i:dowyp) printf("%d ",i); return 0; } |
English