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
#include<bits/stdc++.h>
using namespace std;

//const int duzo = 1000007;

vector<int> dp;
vector <int> xd;
vector<int> wynik;

int main(){
        cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	dp.push_back(0);
	dp.push_back(1);
	for (int i = 2; i <= n; i++){
		if (i%2==0){
			dp.push_back(dp[i/2]);
		}
		else{
			dp.push_back(dp[i/2]+1);
		}
	}
	xd.push_back(0);
	for (int i = 1; i <= n; i++){
		xd.push_back(xd[i-1] + dp[i]);
	}

	while(n > 0){
		int z = lower_bound(xd.begin(), xd.end(), n) - xd.begin();
		wynik.push_back(z);
		n -= dp[z];
	}
	cout << wynik.size() << "\n";
	for(int x : wynik){
		cout << x << " ";
	}
}