#include <cstdio> #include <list> using namespace std; int main() { int n; unsigned int biggest_number = 0; list<int> result; scanf("%d", &n); while(n > 0) { n -= __builtin_popcount(++biggest_number); } while(biggest_number > 0) { if (n + __builtin_popcount(biggest_number) <= 0) { n += __builtin_popcount(biggest_number); } else { result.push_back(biggest_number); } biggest_number--; } printf("%d\n", result.size()); for (auto const& i : result) { printf("%d ", i); } 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 | #include <cstdio> #include <list> using namespace std; int main() { int n; unsigned int biggest_number = 0; list<int> result; scanf("%d", &n); while(n > 0) { n -= __builtin_popcount(++biggest_number); } while(biggest_number > 0) { if (n + __builtin_popcount(biggest_number) <= 0) { n += __builtin_popcount(biggest_number); } else { result.push_back(biggest_number); } biggest_number--; } printf("%d\n", result.size()); for (auto const& i : result) { printf("%d ", i); } return 0; } |