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
#include <bits/stdc++.h>
using namespace std;

int sum[1000005];

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    
    for(int i=1;i<=1000000;i++){
        sum[i] = sum[i-1] + __builtin_popcount(i);
    }

    vector<int> ans;
    int pos = 1000000;
    while(n>0){
        while(sum[pos-1] >= n) pos--;
        ans.push_back(pos);
        n -= __builtin_popcount(pos);
       // cout<<pos<<" "<<n<<endl;
    }

    cout<<ans.size()<<endl;
    for(int pos: ans) cout<<pos<<" ";
    cout<<endl;
}