#include <bits/stdc++.h>
using namespace std;
const int N = 1000002;
int bity(int x) {
int res = 0;
while(x > 0) {
if (x&1)
res++;
x /= 2;
}
return res;
}
int main() {
int n;
cin >> n;
vector <int> liczby;
int sum = 0;
int pos = 0;
for (int i = 1; i < N; i++) {
sum += bity(i);
if (sum >= n) {
pos = i;
break;
}
}
while (pos > 0) {
if (bity(pos) <= sum - n) {
sum -= bity(pos);
}
else {
liczby.push_back(pos);
}
pos--;
}
cout << liczby.size() << "\n";
for (auto &i : liczby) {
cout << 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 35 36 37 38 39 40 41 42 43 44 | #include <bits/stdc++.h> using namespace std; const int N = 1000002; int bity(int x) { int res = 0; while(x > 0) { if (x&1) res++; x /= 2; } return res; } int main() { int n; cin >> n; vector <int> liczby; int sum = 0; int pos = 0; for (int i = 1; i < N; i++) { sum += bity(i); if (sum >= n) { pos = i; break; } } while (pos > 0) { if (bity(pos) <= sum - n) { sum -= bity(pos); } else { liczby.push_back(pos); } pos--; } cout << liczby.size() << "\n"; for (auto &i : liczby) { cout << i << " "; } return 0; } |
English