#include "bits/stdc++.h" // Tomasz Nowak using namespace std; // University of Warsaw using LL = long long; #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) #define ssize(x) int(x.size()) template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) { return o << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) { o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}'; } #ifdef DEBUG #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #else #define debug(...) {} #endif string multiply(LL n, string s) { if(n == 0 or s.empty()) return ""; if(n == 1) return s; if(n < 10 and ssize(s) == 1) return to_string(n) + s; if(n < 10) return to_string(n) + "[" + s + "]"; auto divide_by = [&](int d) { return multiply(d, multiply(n / d, s)) + multiply(n % d, s); }; for(int d : {9, 8, 7, 6, 5, 4, 3, 2}) if(n % d == 0) return divide_by(d); return divide_by(9); } string solve_without_borders(LL n) { if(n == 0) return ""; if(n % 2 == 1) return solve_without_borders(n - 1) + multiply(n - 1, "E") + multiply(n - 1, "AC") + "A"; assert(n % 2 == 0 and n > 0); LL rec = n / 2 - 1; return multiply(rec, "AE") + "A" + multiply(rec, "C") + multiply(2, solve_without_borders(rec)) + multiply(rec, "E") + multiply(rec, multiply(rec, "C") + multiply(rec, "EA") + "E") + multiply(rec, "C") + multiply(rec, "EA") + "EAC" + multiply(2 * rec, "AC") + "A"; } string solve(LL n) { return solve_without_borders(n) + multiply(n, "E") + multiply(n, "C"); } int main() { cin.tie(0)->sync_with_stdio(0); LL n; cin >> n; string out = solve(n); cout << out.data() << '\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 | #include "bits/stdc++.h" // Tomasz Nowak using namespace std; // University of Warsaw using LL = long long; #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) #define ssize(x) int(x.size()) template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) { return o << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) { o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}'; } #ifdef DEBUG #define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' #else #define debug(...) {} #endif string multiply(LL n, string s) { if(n == 0 or s.empty()) return ""; if(n == 1) return s; if(n < 10 and ssize(s) == 1) return to_string(n) + s; if(n < 10) return to_string(n) + "[" + s + "]"; auto divide_by = [&](int d) { return multiply(d, multiply(n / d, s)) + multiply(n % d, s); }; for(int d : {9, 8, 7, 6, 5, 4, 3, 2}) if(n % d == 0) return divide_by(d); return divide_by(9); } string solve_without_borders(LL n) { if(n == 0) return ""; if(n % 2 == 1) return solve_without_borders(n - 1) + multiply(n - 1, "E") + multiply(n - 1, "AC") + "A"; assert(n % 2 == 0 and n > 0); LL rec = n / 2 - 1; return multiply(rec, "AE") + "A" + multiply(rec, "C") + multiply(2, solve_without_borders(rec)) + multiply(rec, "E") + multiply(rec, multiply(rec, "C") + multiply(rec, "EA") + "E") + multiply(rec, "C") + multiply(rec, "EA") + "EAC" + multiply(2 * rec, "AC") + "A"; } string solve(LL n) { return solve_without_borders(n) + multiply(n, "E") + multiply(n, "C"); } int main() { cin.tie(0)->sync_with_stdio(0); LL n; cin >> n; string out = solve(n); cout << out.data() << '\n'; } |