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
46
47
48
#include <iostream>
#include <vector>

int BitPower(int n)
{
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    
    int n; std::cin >> n;
    int sum = 0, number = 0;

    while (sum < n)
    {
        number++;
        sum += BitPower(number);
    }

    std::vector<int> correct;
    int pow = 0;
    for (int i = number; i > 0; i--)
    {
        if (sum != n) {
            pow = BitPower(i);
            if (pow <= sum - n) {
                sum -= pow;
                continue;
            }
        }
        correct.push_back(i);
    }

    std::cout << correct.size() << '\n';
    
    for (int i = 0; i < correct.size(); i++)
        std::cout << correct[i] << " ";
    
    return 0;
}