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

vector<int> wynik;

int ilebit(int n){
    int wynik = 0;
    while(n > 0) {
        if(n % 2 == 1) wynik++;
        n /= 2;
    }
    return wynik;
}

int main() {
    int n, suma = 0, tmp = 1, maxx, ile = 0;
    cin >> n;

    while(suma != n) {
        if(suma + ilebit(tmp) <= n) {
                suma += ilebit(tmp);
                //cout << tmp << " ";
        }
        tmp++;
    }
    tmp -= 2;
    maxx = tmp;
    n -= ilebit(maxx);
    suma = 0;
    tmp = 1;
    while(suma != n) {
        if(suma + ilebit(tmp) <= n) {
            suma += ilebit(tmp);
            wynik.push_back(tmp);
            ile++;
        }
        tmp++;
    }
    reverse(wynik.begin(), wynik.end());
    cout << ile + 1 << endl;
    cout << maxx << " ";
    for(int i = 0; i < wynik.size(); i++) {
        cout << wynik[i] << " ";
    }
}