#include #include #include #include #include using namespace std; struct node{ int next_min; int next_max; int cost; }; int main() { int n; cin >> n; vector table(n + 1); for (int i = 1; i <= n; i++) { int rt = static_cast(sqrt(i)); vector v(rt + 1, INT_MAX), w; for (int j = 1; j <= rt; j++) { v[j] = j + table[i - j * j].cost; } int cost_min = *min_element(v.begin(), v.end()); for (unsigned int i = 0; i < v.size(); i++) { if (v[i] == cost_min) { w.push_back(i); } } if (w.size() > 1) { auto pos = partition(w.begin(), w.end(), [](int& x) { return x % 2; }); sort(w.begin(), pos); sort(pos, w.end(), greater()); } table[i] = { w.front(), w.back(), cost_min }; } bool b = 0; while (n) { int next; if (b) { next = table[n].next_max; } else { next = table[n].next_min; } for (int j = 0; j < next; j++) { cout << b; b ^= 1; } b ^= 1; n -= next * next; } return 0; }