#include<cstdio>
#include<algorithm>
using namespace std;
#define N_MAX 130005
#define B_MAX 130005
int n;
int bounds[N_MAX];
int output[N_MAX];
int res;
int pot;
int main()
{
res=0;
//fill
bounds[0]=0;
bounds[1]=1;
pot=2;
for(int i=2;i<B_MAX-2;i++) {
while(pot*2<=i) {
pot*=2;
}
//printf("%d %d => ",i,pot);
res=bounds[pot-1];
//printf("%d ", res);
res+=bounds[i-pot];
//printf("%d ", bounds[i-pot]);
res+=i-pot+1;
//printf("%d ", i-pot+1);
bounds[i]=res;
//printf(" final: %d\n", res);
}
scanf("%d", &n);
int left=0;
int right=B_MAX-2;
int mid;
int k;
res=0;
while(n>0) {
//printf("N: %d\n",n);
//szukam binarnie liczby
left=0;
while(right-left>0) {
mid=(right+left)/2;
if(bounds[mid] < n) {
left=mid+1;
} else {
right = mid;
}
}
//printf("found (%d,%d) (%d,%d)\n", left, bounds[left], right, bounds[right]);
//wypisuję liczbę
//printf("%d ", left);
output[res++]=left;
//odejmuję to ile ona ma bitów
while(left) {
n-=left&1;
left>>=1;
}
//printf("new N: %d\n",n);
//scanf("%d",&mid);
}
printf("%d\n", res);
for(int i=0;i<res;i++) {
printf("%d ", output[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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include<cstdio> #include<algorithm> using namespace std; #define N_MAX 130005 #define B_MAX 130005 int n; int bounds[N_MAX]; int output[N_MAX]; int res; int pot; int main() { res=0; //fill bounds[0]=0; bounds[1]=1; pot=2; for(int i=2;i<B_MAX-2;i++) { while(pot*2<=i) { pot*=2; } //printf("%d %d => ",i,pot); res=bounds[pot-1]; //printf("%d ", res); res+=bounds[i-pot]; //printf("%d ", bounds[i-pot]); res+=i-pot+1; //printf("%d ", i-pot+1); bounds[i]=res; //printf(" final: %d\n", res); } scanf("%d", &n); int left=0; int right=B_MAX-2; int mid; int k; res=0; while(n>0) { //printf("N: %d\n",n); //szukam binarnie liczby left=0; while(right-left>0) { mid=(right+left)/2; if(bounds[mid] < n) { left=mid+1; } else { right = mid; } } //printf("found (%d,%d) (%d,%d)\n", left, bounds[left], right, bounds[right]); //wypisuję liczbę //printf("%d ", left); output[res++]=left; //odejmuję to ile ona ma bitów while(left) { n-=left&1; left>>=1; } //printf("new N: %d\n",n); //scanf("%d",&mid); } printf("%d\n", res); for(int i=0;i<res;i++) { printf("%d ", output[i]); } printf("\n"); return 0; } |
English