#include <bits/stdc++.h> using namespace std; #define N 1000000 int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<int> suma1(N, 0); vector<int> ile1(N, 0); int n; cin >> n; int i; for (i = 1; i < N; ++i) { ile1[i] = ile1[i / 2] + (i & 1); suma1[i] = suma1[i - 1] + ile1[i]; } int m = n; vector<int> res; while (m > 0) { int j = lower_bound(suma1.begin(), suma1.end(), m) - suma1.begin(); res.push_back(j); m -= ile1[j]; } cout << res.size() << '\n'; for (auto &x : res) cout << x << ' '; cout << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; #define N 1000000 int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<int> suma1(N, 0); vector<int> ile1(N, 0); int n; cin >> n; int i; for (i = 1; i < N; ++i) { ile1[i] = ile1[i / 2] + (i & 1); suma1[i] = suma1[i - 1] + ile1[i]; } int m = n; vector<int> res; while (m > 0) { int j = lower_bound(suma1.begin(), suma1.end(), m) - suma1.begin(); res.push_back(j); m -= ile1[j]; } cout << res.size() << '\n'; for (auto &x : res) cout << x << ' '; cout << '\n'; } |