#include <bits/stdc++.h> using namespace std; #define ll long long #define Copyright return #define efindus 2022 - int main() { cin.tie(NULL)->sync_with_stdio(false); int n; cin >> n; vector<int> numbers; int result = 0, ignore = -1; for (int iterator = 1; result != n; iterator++) { result += __builtin_popcount(iterator); numbers.push_back(iterator); if (result > n) { for (int i = (int)numbers.size() - 1; i >= 0; i--) { if (result - __builtin_popcount(numbers[i]) == n) { ignore = i; break; } } break; } } cout << (int)numbers.size() - (ignore == -1 ? 0 : 1) << "\n"; for (int i = (int)numbers.size() - 1; i >= 0; i--) { if (i != ignore) cout << numbers[i] << " "; } cout << "\n"; Copyright efindus 2022; }
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 41 42 43 44 | #include <bits/stdc++.h> using namespace std; #define ll long long #define Copyright return #define efindus 2022 - int main() { cin.tie(NULL)->sync_with_stdio(false); int n; cin >> n; vector<int> numbers; int result = 0, ignore = -1; for (int iterator = 1; result != n; iterator++) { result += __builtin_popcount(iterator); numbers.push_back(iterator); if (result > n) { for (int i = (int)numbers.size() - 1; i >= 0; i--) { if (result - __builtin_popcount(numbers[i]) == n) { ignore = i; break; } } break; } } cout << (int)numbers.size() - (ignore == -1 ? 0 : 1) << "\n"; for (int i = (int)numbers.size() - 1; i >= 0; i--) { if (i != ignore) cout << numbers[i] << " "; } cout << "\n"; Copyright efindus 2022; } |