#include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out, const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out, const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } string get(long long n, const string& s) { if(n == 0) return ""; if(n == 1) return s; if(n <= 9 && s.length() == 1) return to_string(n) + s; if(n == 2) { if(s.length() == 2) return s + s; else return "2[" + s + "]"; } if(n <= 9) return to_string(n) + "[" + s + "]"; string r = get(n / 9, s); if(r.length() == 1) { r = "9" + r; } else { r = "9[" + r + "]"; } r += get(n % 9, s); return r; } string solve(long long n, int a); vector<string> x = {"A", "E", "C"}; string solve2(long long n, int a) { string r = x[a]; if(n == 1) { return r; } r += solve(n - 2, a); r += get(n - 1, x[(a + 1) % 3] + x[a]); r += get(n - 1, x[(a + 2) % 3] + x[a]); return r; } string solve(long long n, int a) { if(n == 0) return ""; if(n == 1) return x[a] + x[(a + 1) % 3] + x[(a + 2) % 3]; string r = get(n / 2, x[a] + x[(a + 1) % 3]) + x[a] + get(n / 2, x[(a + 2) % 3]); r = get(n / 2, r); r += get(n / 2, x[a]); string s = solve2(n / 2, (a + 1) % 3); if(s.length() >= 3) r += "2[" + s + "]"; else r += s + s; if(n & 1) { r += get(n - 1, x[a] + x[(a + 2) % 3]) + x[a]; r += get(n, x[(a + 1) % 3]); } r += get(n, x[(a + 2) % 3]); return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; cout << solve(n, 0) << endl; 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 | #include <bits/stdc++.h> #define dbg(x) " [" << #x << ": " << (x) << "] " using namespace std; template<typename A,typename B> ostream& operator<<(ostream& out, const pair<A,B>& p) { return out << "(" << p.first << ", " << p.second << ")"; } template<typename T> ostream& operator<<(ostream& out, const vector<T>& c) { out << "{"; for(auto it = c.begin(); it != c.end(); it++) { if(it != c.begin()) out << ", "; out << *it; } return out << "}"; } string get(long long n, const string& s) { if(n == 0) return ""; if(n == 1) return s; if(n <= 9 && s.length() == 1) return to_string(n) + s; if(n == 2) { if(s.length() == 2) return s + s; else return "2[" + s + "]"; } if(n <= 9) return to_string(n) + "[" + s + "]"; string r = get(n / 9, s); if(r.length() == 1) { r = "9" + r; } else { r = "9[" + r + "]"; } r += get(n % 9, s); return r; } string solve(long long n, int a); vector<string> x = {"A", "E", "C"}; string solve2(long long n, int a) { string r = x[a]; if(n == 1) { return r; } r += solve(n - 2, a); r += get(n - 1, x[(a + 1) % 3] + x[a]); r += get(n - 1, x[(a + 2) % 3] + x[a]); return r; } string solve(long long n, int a) { if(n == 0) return ""; if(n == 1) return x[a] + x[(a + 1) % 3] + x[(a + 2) % 3]; string r = get(n / 2, x[a] + x[(a + 1) % 3]) + x[a] + get(n / 2, x[(a + 2) % 3]); r = get(n / 2, r); r += get(n / 2, x[a]); string s = solve2(n / 2, (a + 1) % 3); if(s.length() >= 3) r += "2[" + s + "]"; else r += s + s; if(n & 1) { r += get(n - 1, x[a] + x[(a + 2) % 3]) + x[a]; r += get(n, x[(a + 1) % 3]); } r += get(n, x[(a + 2) % 3]); return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; cout << solve(n, 0) << endl; return 0; } |