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
37
38
39
40
41
42
#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> vec;
    int sum = 0;
    int cnt = 1;
    while(1) {
        vec.push_back(cnt);
        sum = sum + __builtin_popcount(cnt);
        if(sum == n) {
            cout << vec.size() << endl;
            for(int i = vec.size() - 1; i >= 0; i--) {
                cout << vec[i] << " ";
            }
            cout << endl;
            return 0;
        }
        if(sum > n) {
            int banned = -1;
            for(int i = vec.size(); i >= 0; i--) {
                if(sum - n == __builtin_popcount(vec[i])) {
                    banned = i;
                    cout << vec.size() - 1 << endl;
                    for(int j = vec.size() - 1; j >= 0; j--) {
                        if(i != j) cout << vec[j] << " ";
                    }
                    cout << endl;
                    return 0;
                }
            }
        }
        cnt++;
    }
    return 0;
}