#include <cstdio> #include <vector> inline int bits (int n) { int res = 0; while (n) { if (n & 1) { ++res; } n >>= 1; } return res; } int main () { std::vector<int> sums; int sum = 0; int n = 0; while (sum < 1000256) { sums.push_back(sum); ++n; sum += bits(n); } n = sums.size(); int rem; scanf("%d", &rem); std::vector<int> res; for (int i = sums.size() - 2; i >= 0; --i) { if (rem > sums[i]) { res.push_back(i + 1); rem -= bits(i + 1); } } printf("%d\n", res.size()); for (int i = 0; i < res.size(); ++i) { printf(i == res.size() - 1 ? "%d" : "%d ", res[i]); } printf("\n"); 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 37 38 39 40 | #include <cstdio> #include <vector> inline int bits (int n) { int res = 0; while (n) { if (n & 1) { ++res; } n >>= 1; } return res; } int main () { std::vector<int> sums; int sum = 0; int n = 0; while (sum < 1000256) { sums.push_back(sum); ++n; sum += bits(n); } n = sums.size(); int rem; scanf("%d", &rem); std::vector<int> res; for (int i = sums.size() - 2; i >= 0; --i) { if (rem > sums[i]) { res.push_back(i + 1); rem -= bits(i + 1); } } printf("%d\n", res.size()); for (int i = 0; i < res.size(); ++i) { printf(i == res.size() - 1 ? "%d" : "%d ", res[i]); } printf("\n"); return 0; } |