#include <bits/stdc++.h> using namespace std; typedef long long lld; string base1[] { "", "A", "AEACA" }; string repeat(const string &s, lld times) { if (times == 0) return ""; if (times < 10) { if (s.size() == 1) return times == 1 ? s : to_string(times) + s; if (times * s.size() <= s.size() + 3) { string res = ""; while (times--) res += s; return res; } return to_string(times) + '[' + s + ']'; } return "9[" + repeat(s, times / 9) + ']' + repeat(s, times % 9); } string tree1(lld n) { if (n <= 2) return base1[n]; string res = n % 2 == 1 ? repeat("AE", n-1) + "A" : repeat("AAECE", n-2) + "AEACA"; n = (n-1)/2; res += repeat(repeat("CA", n) + "C" + repeat("E", n), n) + repeat("C", n); return res + (n == 1 ? tree1(n) + tree1(n) : "2[" + tree1(n) + ']'); } string draw(lld n) { return tree1(n) + repeat("E", n) + repeat("C", n); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); lld n; cin >> n; cout << draw(n) << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long lld; string base1[] { "", "A", "AEACA" }; string repeat(const string &s, lld times) { if (times == 0) return ""; if (times < 10) { if (s.size() == 1) return times == 1 ? s : to_string(times) + s; if (times * s.size() <= s.size() + 3) { string res = ""; while (times--) res += s; return res; } return to_string(times) + '[' + s + ']'; } return "9[" + repeat(s, times / 9) + ']' + repeat(s, times % 9); } string tree1(lld n) { if (n <= 2) return base1[n]; string res = n % 2 == 1 ? repeat("AE", n-1) + "A" : repeat("AAECE", n-2) + "AEACA"; n = (n-1)/2; res += repeat(repeat("CA", n) + "C" + repeat("E", n), n) + repeat("C", n); return res + (n == 1 ? tree1(n) + tree1(n) : "2[" + tree1(n) + ']'); } string draw(lld n) { return tree1(n) + repeat("E", n) + repeat("C", n); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); lld n; cin >> n; cout << draw(n) << '\n'; } |