#include <bits/stdc++.h> using namespace std; #define MAX_N 2000007 int n, mass, it; int counta[MAX_N]; vector<int> v; void sito(int x) { for (int i = 0; i <= x; i++) { if(i % 2 == 0) { counta[i+1] = counta[i] + 1; } counta[i*2] = counta[i]; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; sito(n); mass = 0; it = 0; while (mass < n) { mass += counta[it]; it++; } it--; while (n > 0) { if (n - counta[it] >= 0 && mass - counta[it] < n) { n -= counta[it]; v.push_back(it); } mass -= counta[it]; it--; } cout << v.size() << "\n"; for (auto i : v) { cout << i << " "; } }
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 | #include <bits/stdc++.h> using namespace std; #define MAX_N 2000007 int n, mass, it; int counta[MAX_N]; vector<int> v; void sito(int x) { for (int i = 0; i <= x; i++) { if(i % 2 == 0) { counta[i+1] = counta[i] + 1; } counta[i*2] = counta[i]; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; sito(n); mass = 0; it = 0; while (mass < n) { mass += counta[it]; it++; } it--; while (n > 0) { if (n - counta[it] >= 0 && mass - counta[it] < n) { n -= counta[it]; v.push_back(it); } mass -= counta[it]; it--; } cout << v.size() << "\n"; for (auto i : v) { cout << i << " "; } } |