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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector pot = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576}; vector a(n+1); a[0] = 0; a[1] = a[2] = 1; int ii = 0; vector s(n+1); s[0] = 0; int ans = 0; bool flag = 0; while(pot[ii] <= n) { for(int i = pot[ii]; i < min(2* pot[ii], n+1); i++) { a[i] = a[i - pot[ii]] + 1; s[i] = a[i] + s[i-1]; if(s[i] >= n) { ans = i; flag = 1; break; } } if(flag) break; ii++; } // for(auto x : a) // { // cout << x << ' '; // } // cout << '\n'; int suma = s[ans]; vector wyn; for(int i = ans; i > 0; i--) { if(suma - n >= a[i]) { suma -= a[i]; } else { wyn.push_back(i); } } cout << wyn.size()<<'\n'; for(auto x : wyn) cout << x << ' '; cout << '\n'; // cout << suma << '\n'; }