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
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
int main(){
    std::ios_base::sync_with_stdio(0);
    int n,sum=0;
    std::cin>>n;
    int i=0;
    std::vector<int> result;
    while (sum<n){
        i++;
        sum+=__builtin_popcount(i);
    }
    while(i>0){
        if(__builtin_popcount(i)<=sum-n){
            sum-=__builtin_popcount(i);
        }else{
            result.emplace_back(i);
        }
        i--;
    }
    std::cout<<result.size()<<std::endl;
    for(auto i:result)
        std::cout<<i<<" ";
    std::cout<<std::endl;
}