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

using namespace std;
typedef unsigned int uint;
#define pb push_back

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    uint n;
    cin >> n;

    uint sum = 0, x = 0;
    vector <uint> ans;
    while(sum < n) {
        x++;
        sum += __builtin_popcount(x);
    }
    while(sum >= n && x > 0){
        if(sum - __builtin_popcount(x) >= n) sum -= __builtin_popcount(x);
        else ans.pb(x);
        x--;
    }
    cout << ans.size() << "\n";
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; 
    cout << "\n";

    return 0;
}