#include<bits/stdc++.h>
using namespace std;
int pre[1000007];
int a[1000007];
int ile[1000007];
int suma;
int ile1(int x) {
suma=0;
while(x>=1) {
if (x%2==1)
suma++;
x/=2;
}
return suma;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,cos,imaks;
cin >> n;
for (int i=1; cos<n; i++) {
ile[i]=ile1(i);
pre[i]=pre[i-1]+ile[i];
cos=pre[i];
imaks=i;
}
int ileodjac=cos-n;
int licznik=0;
if (ileodjac==0)
cout << imaks <<"\n";
else cout << imaks-1<<"\n";
for (int i=imaks; i>=1; i--) {
if (ile[i]==ileodjac and licznik==0) {
licznik++;
}
else 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 | #include<bits/stdc++.h> using namespace std; int pre[1000007]; int a[1000007]; int ile[1000007]; int suma; int ile1(int x) { suma=0; while(x>=1) { if (x%2==1) suma++; x/=2; } return suma; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,cos,imaks; cin >> n; for (int i=1; cos<n; i++) { ile[i]=ile1(i); pre[i]=pre[i-1]+ile[i]; cos=pre[i]; imaks=i; } int ileodjac=cos-n; int licznik=0; if (ileodjac==0) cout << imaks <<"\n"; else cout << imaks-1<<"\n"; for (int i=imaks; i>=1; i--) { if (ile[i]==ileodjac and licznik==0) { licznik++; } else cout << i << " "; } return 0; } |
English