#include <iostream> #include <stack> using namespace std; const int MAX_N = 1000009; int output[MAX_N]; int bin_sum_val[MAX_N]; int output_iterator = 0; int output_iterator2 = 0; int bin_sum(int a){ int w = 0; while(a > 0){ if((a % 2) == 1) w++; a/=2; } return w; } int fast_read(){ char c; int w = 0; c = getchar_unlocked(); while(c < '0' or c > '9') c = getchar_unlocked(); while('9'>= c and c>= '0'){ w = w * 10 + (c - '0'); c = getchar_unlocked(); } return w; } void fast_output(int a){ stack <int> output_stack; while(a > 0){ output_stack.push(a % 10); a/=10; } while(!output_stack.empty()){ putchar_unlocked(output_stack.top() + '0'); output_stack.pop(); } putchar_unlocked(' '); } int main() { int n; //cin>>n; n = fast_read(); int cur_bin_sum; int i = 1; int countt = 0; cur_bin_sum = bin_sum(i); //i++; do{ i++; n-= cur_bin_sum; output[output_iterator] = i - 1; bin_sum_val[output_iterator] = cur_bin_sum; output_iterator++; output_iterator2++; cur_bin_sum = bin_sum(i); countt++; } while(cur_bin_sum <= n); int too_much = cur_bin_sum - n; output_iterator2--; if(n != 0) countt++; while(too_much > 0 and n != 0){ if(bin_sum_val[output_iterator2] <= too_much){ too_much-= bin_sum_val[output_iterator2]; output[output_iterator2] = -1; countt--; } output_iterator2--; } //cout<<countt + 1<<"\n"; fast_output(countt); putchar_unlocked('\n'); //cout<<i<<" "; if(n != 0) fast_output(i); for(int i = output_iterator; i >= 0; i--){ //if(output[i] > 0) cout<<output[i]<<" "; if(output[i] > 0) fast_output(output[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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #include <iostream> #include <stack> using namespace std; const int MAX_N = 1000009; int output[MAX_N]; int bin_sum_val[MAX_N]; int output_iterator = 0; int output_iterator2 = 0; int bin_sum(int a){ int w = 0; while(a > 0){ if((a % 2) == 1) w++; a/=2; } return w; } int fast_read(){ char c; int w = 0; c = getchar_unlocked(); while(c < '0' or c > '9') c = getchar_unlocked(); while('9'>= c and c>= '0'){ w = w * 10 + (c - '0'); c = getchar_unlocked(); } return w; } void fast_output(int a){ stack <int> output_stack; while(a > 0){ output_stack.push(a % 10); a/=10; } while(!output_stack.empty()){ putchar_unlocked(output_stack.top() + '0'); output_stack.pop(); } putchar_unlocked(' '); } int main() { int n; //cin>>n; n = fast_read(); int cur_bin_sum; int i = 1; int countt = 0; cur_bin_sum = bin_sum(i); //i++; do{ i++; n-= cur_bin_sum; output[output_iterator] = i - 1; bin_sum_val[output_iterator] = cur_bin_sum; output_iterator++; output_iterator2++; cur_bin_sum = bin_sum(i); countt++; } while(cur_bin_sum <= n); int too_much = cur_bin_sum - n; output_iterator2--; if(n != 0) countt++; while(too_much > 0 and n != 0){ if(bin_sum_val[output_iterator2] <= too_much){ too_much-= bin_sum_val[output_iterator2]; output[output_iterator2] = -1; countt--; } output_iterator2--; } //cout<<countt + 1<<"\n"; fast_output(countt); putchar_unlocked('\n'); //cout<<i<<" "; if(n != 0) fast_output(i); for(int i = output_iterator; i >= 0; i--){ //if(output[i] > 0) cout<<output[i]<<" "; if(output[i] > 0) fast_output(output[i]); } return 0; } |