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;

const int N = 1e6+10;
int W[N];

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,i=1;
  cin>>n;
  while(n > W[i-1])
  {
    int cmp = 0;
    for(int j=0;i>=(1<<j);j++)
      if((1<<j) & i)
        cmp++;
    W[i] = cmp + W[i-1], i++;
  }
  i--;
  vector<int>A;
  while(n)
  {
    int cmp = 0;
    for(int j=0;i>=(1<<j);j++)
      if((1<<j) & i)
        cmp++;
    if(W[i-1] < n)
      n -= cmp, A.push_back(i);
    i--;
  }
  cout<<A.size()<<"\n";
  for(auto& elm : A)
    cout<<elm<<" ";
}