#include <iostream>
#include<cstdio>
using namespace std;
int t[121000];
int main()
{
int n;
cin >> n;
int a,s;
int lst = 0;
for (int i=1;; i++)
{
a = __builtin_popcount(i);
s+=a;
if (s>=n)
{
lst=i;
break;
}
}
int c = lst;
for (int i=lst-1; i>0; i--)
{
a = __builtin_popcount(i);
if (s - a >= n)
{
s -= a;
t[i] = 1;
c--;
}
}
printf("%d\n",c);
for (int i=lst; i>0; i--)
{
if (!t[i])
{
printf("%d ", i);
}
}
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <iostream> #include<cstdio> using namespace std; int t[121000]; int main() { int n; cin >> n; int a,s; int lst = 0; for (int i=1;; i++) { a = __builtin_popcount(i); s+=a; if (s>=n) { lst=i; break; } } int c = lst; for (int i=lst-1; i>0; i--) { a = __builtin_popcount(i); if (s - a >= n) { s -= a; t[i] = 1; c--; } } printf("%d\n",c); for (int i=lst; i>0; i--) { if (!t[i]) { printf("%d ", i); } } printf("\n"); return 0; } |
English