#include<bits/stdc++.h> #define int long long using namespace std; string I(int n); string III(int n); string R(int n); string Repeat(string s, int times); string Repeat_less_9(string s, int times); vector <int> break_to_9(int n); string I(int n) { if (n == 0) return ""; if (n == 1) return "A"; string ans = ""; ans += "A"; ans += III(n - 2); ans += Repeat("EA", n - 1); ans += Repeat("CA", n - 1); return ans; } string III(int n) { if (n == 0) return ""; if (n == 1) return "AEC"; string ans = ""; if (n % 2 == 0) { ans += Repeat_less_9(I(n / 2), 2); ans += Repeat("E", n / 2); ans += R(n / 2); ans += Repeat("C", n / 2); return ans; } ans += "A"; ans += III(n - 1); ans += Repeat("EA", n - 1); ans += "E"; ans += Repeat("C", n); return ans; } string R(int n) { if (n == 0) return ""; string ans = ""; ans += Repeat(Repeat("DF", n - 1) + "D" + Repeat("B", n), n); ans += Repeat("F", n); ans += Repeat("E", n); ans += Repeat("C", n); return ans; } vector <int> break_to_9(int n) { vector <int> ans; while (n > 0){ ans.push_back(n % 9); n -= (n % 9); n /= 9; } reverse(ans.begin(), ans.end()); return ans; } string Repeat_less_9(string s, int times) { if (times == 0) return ""; if (times == 1) return s; if (s.size() == 0) return ""; if (s.size() == 1) return to_string(times) + s; string ans = to_string(times) + "[" + s + "]"; return ans; } string Repeat(string s, int times) { vector <int> v = break_to_9(times); string ans = ""; for (int i : v){ ans = Repeat_less_9(s, i) + Repeat_less_9(ans, 9); } return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; cout << III(n) << "\n"; 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include<bits/stdc++.h> #define int long long using namespace std; string I(int n); string III(int n); string R(int n); string Repeat(string s, int times); string Repeat_less_9(string s, int times); vector <int> break_to_9(int n); string I(int n) { if (n == 0) return ""; if (n == 1) return "A"; string ans = ""; ans += "A"; ans += III(n - 2); ans += Repeat("EA", n - 1); ans += Repeat("CA", n - 1); return ans; } string III(int n) { if (n == 0) return ""; if (n == 1) return "AEC"; string ans = ""; if (n % 2 == 0) { ans += Repeat_less_9(I(n / 2), 2); ans += Repeat("E", n / 2); ans += R(n / 2); ans += Repeat("C", n / 2); return ans; } ans += "A"; ans += III(n - 1); ans += Repeat("EA", n - 1); ans += "E"; ans += Repeat("C", n); return ans; } string R(int n) { if (n == 0) return ""; string ans = ""; ans += Repeat(Repeat("DF", n - 1) + "D" + Repeat("B", n), n); ans += Repeat("F", n); ans += Repeat("E", n); ans += Repeat("C", n); return ans; } vector <int> break_to_9(int n) { vector <int> ans; while (n > 0){ ans.push_back(n % 9); n -= (n % 9); n /= 9; } reverse(ans.begin(), ans.end()); return ans; } string Repeat_less_9(string s, int times) { if (times == 0) return ""; if (times == 1) return s; if (s.size() == 0) return ""; if (s.size() == 1) return to_string(times) + s; string ans = to_string(times) + "[" + s + "]"; return ans; } string Repeat(string s, int times) { vector <int> v = break_to_9(times); string ans = ""; for (int i : v){ ans = Repeat_less_9(s, i) + Repeat_less_9(ans, 9); } return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; cout << III(n) << "\n"; return 0; } |