#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
int tab[121005], i, n;
VI v;
int main() {
tab[0] = 0;
for (i=1;i<121000;i++) tab[i] = tab[i - 1] + __builtin_popcount(i);
scanf("%d", &n);
i = 1;
while (tab[i] < n) i++;
v.clear();
while (n > 0) {
while (tab[i - 1] >= n) i--;
v.pb(i);
n -= __builtin_popcount(i);
i--;
}
printf("%d\n", v.size());
for (auto& w : v) printf("%d ", w);
printf("\n");
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 | #include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair <int,int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; int tab[121005], i, n; VI v; int main() { tab[0] = 0; for (i=1;i<121000;i++) tab[i] = tab[i - 1] + __builtin_popcount(i); scanf("%d", &n); i = 1; while (tab[i] < n) i++; v.clear(); while (n > 0) { while (tab[i - 1] >= n) i--; v.pb(i); n -= __builtin_popcount(i); i--; } printf("%d\n", v.size()); for (auto& w : v) printf("%d ", w); printf("\n"); return 0; } |
English