#include <bits/stdc++.h> #define ll long long const ll NINE = 9; std::string draw_repeat(ll n, std::string s) { if (n == 0) return ""; if (n == 1) { std::string z = s; return z; } ll r = n % NINE; n /= NINE; std::string z = ""; if (n > 0) { z = "9["; z += draw_repeat(n, s); z += "]"; } if (r > 0) { z += (char)(r + '0'); if (s.length() == 1) { z += s; } else { z += "["; z += s; z += "]"; } } return z; } std::string draw(ll n) { std::string s = ""; if (n == 1) { s = "AEC"; } else if (n == 2) { s = "AAECEAECC"; } else if (n % 2 == 1) { s = draw_repeat(n, "A"); s += draw_repeat(n-1, "EC"); s += "E"; s += draw(n-1); s += "C"; } else { ll k = (n-2)/2; s = "F"; std::string z = draw(k); z += draw_repeat(k, "BF"); s += draw_repeat(2, z); s += draw_repeat(2*k, "FD"); std::string t = draw_repeat(k, "B"); s += t; std::string h = draw_repeat(k-1, "DF"); h += "D"; z = h + t; s += draw_repeat(k-1, z); s += h; s += draw_repeat(k+1, "F"); s += draw_repeat(n, "B"); s += "DFDB"; s += draw_repeat(n-1, "D"); } return s; } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); ll n; std::cin >> n; std::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 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 | #include <bits/stdc++.h> #define ll long long const ll NINE = 9; std::string draw_repeat(ll n, std::string s) { if (n == 0) return ""; if (n == 1) { std::string z = s; return z; } ll r = n % NINE; n /= NINE; std::string z = ""; if (n > 0) { z = "9["; z += draw_repeat(n, s); z += "]"; } if (r > 0) { z += (char)(r + '0'); if (s.length() == 1) { z += s; } else { z += "["; z += s; z += "]"; } } return z; } std::string draw(ll n) { std::string s = ""; if (n == 1) { s = "AEC"; } else if (n == 2) { s = "AAECEAECC"; } else if (n % 2 == 1) { s = draw_repeat(n, "A"); s += draw_repeat(n-1, "EC"); s += "E"; s += draw(n-1); s += "C"; } else { ll k = (n-2)/2; s = "F"; std::string z = draw(k); z += draw_repeat(k, "BF"); s += draw_repeat(2, z); s += draw_repeat(2*k, "FD"); std::string t = draw_repeat(k, "B"); s += t; std::string h = draw_repeat(k-1, "DF"); h += "D"; z = h + t; s += draw_repeat(k-1, z); s += h; s += draw_repeat(k+1, "F"); s += draw_repeat(n, "B"); s += "DFDB"; s += draw_repeat(n-1, "D"); } return s; } int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); ll n; std::cin >> n; std::cout << draw(n) << "\n"; } |