#include <iostream> #include <cmath> using namespace std; int tab[500000] = {}; int tabbraklicz[1000] = {}; int tabusulicz[100] = {}; int main() { int x, braklicz, l = 0, a = 0,f=0,j, v = 0; bool list, go = true; cin >> x; for (int z = 0; z < 500000; z++) { int licz = 0; int rem; int n = z; while (n != 0) { rem = n % 2; n /= 2; licz += rem ; } tab[z] = licz; } int z = 0; int miej = 0; while (z < x) { miej++; z += tab[miej]; } if (z == x) { for (int o = miej; o > 0; o--) { cout << o<<" "; } } else { int i = miej; for (int o = 1; o <= miej; o++) { int sum = 0, g = 0, pocz, rem, kon; i--; f++; tabbraklicz[f] = tab[o]; for (int y = 0; y < f; y++) { g = pow(2, y+1); pocz = g - 1; kon = pow(2, y); } for (int q = pocz; q >= kon; q--) { int r = q; l = 0; while (r != 0) { l++; rem = r % 2; r /= 2; if (rem == 1) { sum += tabbraklicz[l]; } } r = q; if (sum == z - x) { //cout << sum; l = 0; while (r != 0) { if (r % 2 == 1) { v++; } rem = r % 2; r /= 2; l++; int h = pow(2,q); tabusulicz[l] = h-q+l; } if (v != 1) { v--; } break; } } } cout << miej - v << endl;; for (int e = miej; e >0; e--) { go = true; for (int g = v; g > 0; g--) { if (tabusulicz[g] == e) { go = false; } } if (go) { cout << e<<" "; } } } 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 | #include <iostream> #include <cmath> using namespace std; int tab[500000] = {}; int tabbraklicz[1000] = {}; int tabusulicz[100] = {}; int main() { int x, braklicz, l = 0, a = 0,f=0,j, v = 0; bool list, go = true; cin >> x; for (int z = 0; z < 500000; z++) { int licz = 0; int rem; int n = z; while (n != 0) { rem = n % 2; n /= 2; licz += rem ; } tab[z] = licz; } int z = 0; int miej = 0; while (z < x) { miej++; z += tab[miej]; } if (z == x) { for (int o = miej; o > 0; o--) { cout << o<<" "; } } else { int i = miej; for (int o = 1; o <= miej; o++) { int sum = 0, g = 0, pocz, rem, kon; i--; f++; tabbraklicz[f] = tab[o]; for (int y = 0; y < f; y++) { g = pow(2, y+1); pocz = g - 1; kon = pow(2, y); } for (int q = pocz; q >= kon; q--) { int r = q; l = 0; while (r != 0) { l++; rem = r % 2; r /= 2; if (rem == 1) { sum += tabbraklicz[l]; } } r = q; if (sum == z - x) { //cout << sum; l = 0; while (r != 0) { if (r % 2 == 1) { v++; } rem = r % 2; r /= 2; l++; int h = pow(2,q); tabusulicz[l] = h-q+l; } if (v != 1) { v--; } break; } } } cout << miej - v << endl;; for (int e = miej; e >0; e--) { go = true; for (int g = v; g > 0; g--) { if (tabusulicz[g] == e) { go = false; } } if (go) { cout << e<<" "; } } } return 0; } |