#include <bit> #include <iostream> #include <vector> int main() { uint64_t in; std::cin >> in; std::vector<uint64_t> sums(1'000'000); sums[0] = 0; uint64_t i = 0; while (sums[i] < in) { sums[i + 1] = sums[i] + std::__popcount(i + 1); i += 1; } std::vector<uint64_t> output; output.push_back(i); in -= std::__popcount(i); i -= 1; while (in > 0) { while (sums[i - 1] >= in) { i -= 1; } output.push_back(i); in -= std::__popcount(i); i -= 1; } std::cout << output.size() << "\n"; for (auto data: output) { std::cout << data << " "; } std::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 | #include <bit> #include <iostream> #include <vector> int main() { uint64_t in; std::cin >> in; std::vector<uint64_t> sums(1'000'000); sums[0] = 0; uint64_t i = 0; while (sums[i] < in) { sums[i + 1] = sums[i] + std::__popcount(i + 1); i += 1; } std::vector<uint64_t> output; output.push_back(i); in -= std::__popcount(i); i -= 1; while (in > 0) { while (sums[i - 1] >= in) { i -= 1; } output.push_back(i); in -= std::__popcount(i); i -= 1; } std::cout << output.size() << "\n"; for (auto data: output) { std::cout << data << " "; } std::cout << "\n"; } |