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
#include <bits/stdc++.h>
using namespace std;
long long n, sum, k, roz, it, all;
queue <long long> kol;
int main() {
    cin >> n;
    it = 0;
    while (sum < n) {
        it++;
        sum += __builtin_popcount(it);
    }
    roz = sum - n;
    k = it;
    all = it;
    while (true) {
        if (roz - __builtin_popcount(it) >= 0) {
            roz -=  __builtin_popcount(it);
            kol.push(it);
            k--;
        }
        if (roz == 0) break;
        it--;
    }
    cout << k << endl;
    for(int i = all; i >= 0; i--) {
        if (i == kol.front()) kol.pop();
        else cout << i << " ";
    }
}