#include <iostream>
#include <bit>
#include <stdio.h>
#include<vector>
using namespace std;
int main()
{
int n;
cin >> n;
int pom = 1;
while (n > 0) {
n -= __builtin_popcount(pom);
pom++;
}
pom--;
int naj = pom;
vector<bool> wypisz(pom+1, 1);
int licz = 0;
while (n != 0) {
pom--;
if (-n == __builtin_popcount(pom)) {
wypisz[pom] = 0;
licz++;
break;
}
if (-n > __builtin_popcount(pom)) {
wypisz[pom] = 0;
licz++;
n += __builtin_popcount(pom);
}
}
cout<<naj - licz<<endl;
for (int i = naj; i > 0; i--) {
if (wypisz[i])cout << i<<' ';
// cout<<"hej";
}
}
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 | #include <iostream> #include <bit> #include <stdio.h> #include<vector> using namespace std; int main() { int n; cin >> n; int pom = 1; while (n > 0) { n -= __builtin_popcount(pom); pom++; } pom--; int naj = pom; vector<bool> wypisz(pom+1, 1); int licz = 0; while (n != 0) { pom--; if (-n == __builtin_popcount(pom)) { wypisz[pom] = 0; licz++; break; } if (-n > __builtin_popcount(pom)) { wypisz[pom] = 0; licz++; n += __builtin_popcount(pom); } } cout<<naj - licz<<endl; for (int i = naj; i > 0; i--) { if (wypisz[i])cout << i<<' '; // cout<<"hej"; } } |
English