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
//Jakub Nowak XIV LO Wroclaw
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

const int N = 1e6+7;

int T[N];//T[k] = suma zapalonych bitow liczby i, dla i <= k

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int i=1; i<N; i++) T[i]=T[i-1]+__builtin_popcount(i);
    int n;
    vector<int> odp;
    cin>>n;
    for(int x=1e6; n; x--) {
        if(/*T[x]>=n&&*/T[x-1]<n) {
            //cout<<x<<" ";
            odp.pb(x);
            n-=__builtin_popcount(x);
            //x=0;
        }
    }
    cout<<odp.size()<<"\n";
    for(auto u:odp) cout<<u<<" ";
}