#include <bits/stdc++.h> using namespace std; void print(vector<int> const& v) { cout << v.size() << '\n'; for (size_t i = 0; i < v.size(); ++i) cout << v[i] << (i == v.size() - 1 ? '\n' : ' '); } void solve() { int n, s = 0, i = 0; cin >> n; while (s < n) s += __builtin_popcount(++i); s -= n; vector<int> res; while (i > 0) { int cand = s - __builtin_popcount(i); if (cand < 0) res.push_back(i); else s = cand; --i; } print(res); } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }
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 | #include <bits/stdc++.h> using namespace std; void print(vector<int> const& v) { cout << v.size() << '\n'; for (size_t i = 0; i < v.size(); ++i) cout << v[i] << (i == v.size() - 1 ? '\n' : ' '); } void solve() { int n, s = 0, i = 0; cin >> n; while (s < n) s += __builtin_popcount(++i); s -= n; vector<int> res; while (i > 0) { int cand = s - __builtin_popcount(i); if (cand < 0) res.push_back(i); else s = cand; --i; } print(res); } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; } |