#include <vector> #include <iostream> using namespace std; string lib = "1"; int moc = 1; int x = 1; vector<int> ciong; void amplify() {x++; int siz = (int)lib.size(); int i = 0; while (lib[i] == '1') { lib[i] = '0'; moc--; if (i + 1 == siz) { lib += '1'; moc++; return; } } lib[i] = '1'; moc++; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int w = 0; while (w + moc <= n) { w+= moc; amplify(); } int maxis = x; while (w + moc !=n) { amplify(); } cout << x << " "; for (int i = x; i > 0; i--) { 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 58 59 60 61 62 63 | #include <vector> #include <iostream> using namespace std; string lib = "1"; int moc = 1; int x = 1; vector<int> ciong; void amplify() {x++; int siz = (int)lib.size(); int i = 0; while (lib[i] == '1') { lib[i] = '0'; moc--; if (i + 1 == siz) { lib += '1'; moc++; return; } } lib[i] = '1'; moc++; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int w = 0; while (w + moc <= n) { w+= moc; amplify(); } int maxis = x; while (w + moc !=n) { amplify(); } cout << x << " "; for (int i = x; i > 0; i--) { cout << i << " "; } return 0; } |