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
#include <iostream>
#include <vector>
using namespace std;

int bitCount(unsigned int u)
    {
         unsigned int uCount;

         uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
         return ((uCount + (uCount >> 3)) & 030707070707) % 63;
    }

int main() {
	
	int n;
	cin >> n;
	int sum = 0;
	
	int i=0;
	vector<int> result;
	while (sum < n)
	{
		i++;
		sum += bitCount(i);
	}
	
	while (n > 0)
	{
		sum -= bitCount(i);
		if (sum < n)
		{
			result.push_back(i);
			n -= bitCount(i);
		}
		i--;
	}
	
	cout << result.size() << endl;
	for (int j=0; j<result.size()-1; j++)
		cout << result[j] << " ";
	cout << result[result.size()-1] << " ";
}