// Autor: Adam Szymaszkiewicz #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { vector<int> v(125003); for (int i = 0; i < 125000; i++) { int sum = 0; int a = i+1; while (a > 0) { sum += a%2; a /= 2; } v[i] = sum; } int n; cin >> n; int a = 0; int indeks = 0; for (int i = 0; i < v.size(); i++) { a += v[i]; if (a >= n) { indeks = i; break; } } vector<int> wyn; for (int i = indeks; i >= 0; i--) { if (a > n && v[i] <= a-n) a -= v[i]; else wyn.push_back(i+1); } cout << wyn.size() << "\n"; for (int i = 0; i < wyn.size(); i++) cout << wyn[i] << " "; 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 34 35 36 37 38 39 40 41 42 43 44 45 | // Autor: Adam Szymaszkiewicz #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { vector<int> v(125003); for (int i = 0; i < 125000; i++) { int sum = 0; int a = i+1; while (a > 0) { sum += a%2; a /= 2; } v[i] = sum; } int n; cin >> n; int a = 0; int indeks = 0; for (int i = 0; i < v.size(); i++) { a += v[i]; if (a >= n) { indeks = i; break; } } vector<int> wyn; for (int i = indeks; i >= 0; i--) { if (a > n && v[i] <= a-n) a -= v[i]; else wyn.push_back(i+1); } cout << wyn.size() << "\n"; for (int i = 0; i < wyn.size(); i++) cout << wyn[i] << " "; cout << "\n"; } |