// Jakub Rozek
// Muzyka pop 2
// PA 2022 C r2
// czas: n/x
// pami: n/x
#include "bits/stdc++.h"
using namespace std;
const int N=1000006;
int n,p;
vector <int> suma;
vector <int> odp;
int ilebitow(int a)
{
int w=0;
while(a)
{
if(a%2) ++w;
a/=2;
}
return w;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
suma.push_back(0);
while(true)
{
++p;
suma.push_back(suma[p-1]+ilebitow(p));
if(suma[p]>=n) break;
}
while(n)
{
if(suma[p]<n)
{
odp.push_back(p+1);
n-=suma[p+1]-suma[p];
}
--p;
}
cout<<odp.size()<<"\n";
for(int i:odp) 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 45 46 47 48 49 50 51 52 53 54 55 56 57 | // Jakub Rozek // Muzyka pop 2 // PA 2022 C r2 // czas: n/x // pami: n/x #include "bits/stdc++.h" using namespace std; const int N=1000006; int n,p; vector <int> suma; vector <int> odp; int ilebitow(int a) { int w=0; while(a) { if(a%2) ++w; a/=2; } return w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; suma.push_back(0); while(true) { ++p; suma.push_back(suma[p-1]+ilebitow(p)); if(suma[p]>=n) break; } while(n) { if(suma[p]<n) { odp.push_back(p+1); n-=suma[p+1]-suma[p]; } --p; } cout<<odp.size()<<"\n"; for(int i:odp) cout<<i<<" "; return 0; } |
English