#include <bits/stdc++.h> using namespace std; typedef long long lld; constexpr int INF = (1<<30) - 1; constexpr lld LINF = (1LL << 62) - 1; constexpr int MAX_N = 1000000; string repeat(lld rep, string inside) { if (rep < 1) { return ""; } if (rep == 1) { return inside; } for (int digit = 9; digit >= 2; digit--) { if (rep % digit == 0) { string ret = ""; ret += ('0' + digit); ret += '['; ret += repeat(rep/digit, inside); ret += ']'; // printf("%d["); // repeat(rep/9, inside); // printf("]", digit); return ret; } } for (int rep2 = 1; rep2 < rep; rep2++) { if ((rep - rep2) % 9 == 0) { // repeat(rep - rep2, inside); // repeat(rep2, inside); string ret = repeat(rep - rep2, inside); ret += repeat(rep2, inside); return ret; } } } /* void repeat(lld rep, char* inside) { repeat(rep, [inside](void) {printf("%s", inside);}); } //*/ string repeat(lld rep, char inside) { char s[2] = "A"; s[0] = inside; return repeat(rep, s); } string row(lld width) { string ret = repeat(width, "A"); ret += repeat(width, "EC"); ret += 'E'; return ret; } string Lu_triangle(lld side); string Lu_D_triangle(lld side) { string ret = ""; ret += repeat(2, Lu_triangle(side/2)); ret += repeat(side/2, 'A'); string inside = ""; inside += repeat(side/2, 'E'); inside += repeat(side/2, "AC"); inside += 'A'; ret += repeat(side/2, inside); return ret; } // left up is the only side left string Lu_triangle(lld side) { if (side == 1) { return "C"; } if (side == 2) { return "CACEC"; } string ret = Lu_D_triangle(side/2); string inside = "C"; inside += repeat(side/2-1, "AC"); inside += repeat(side/2, 'E'); repeat(side/2, inside); ret += Lu_triangle(side/2); return ret; } string full_triangle(lld side) { if (side < 1) { return ""; } if (side == 1) { return "AEC"; } int pow = 1; while (pow * 2 <= side) { pow *= 2; } string ret = repeat(pow, "A"); // write_cut_trinagle_bottom(pow); lld row_lenght = side - pow; ret += repeat(pow, row(row_lenght)); ret += full_triangle(side - pow); ret += Lu_triangle(pow); return ret; } void solve(int test_number) { lld n; scanf("%lld", &n); cout << full_triangle(n) << endl; } int main() { int test_number = 1; // scanf("%d", &test_number); for (int test_id = 0; test_id < test_number; ++test_id) { solve(test_number); } }
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #include <bits/stdc++.h> using namespace std; typedef long long lld; constexpr int INF = (1<<30) - 1; constexpr lld LINF = (1LL << 62) - 1; constexpr int MAX_N = 1000000; string repeat(lld rep, string inside) { if (rep < 1) { return ""; } if (rep == 1) { return inside; } for (int digit = 9; digit >= 2; digit--) { if (rep % digit == 0) { string ret = ""; ret += ('0' + digit); ret += '['; ret += repeat(rep/digit, inside); ret += ']'; // printf("%d["); // repeat(rep/9, inside); // printf("]", digit); return ret; } } for (int rep2 = 1; rep2 < rep; rep2++) { if ((rep - rep2) % 9 == 0) { // repeat(rep - rep2, inside); // repeat(rep2, inside); string ret = repeat(rep - rep2, inside); ret += repeat(rep2, inside); return ret; } } } /* void repeat(lld rep, char* inside) { repeat(rep, [inside](void) {printf("%s", inside);}); } //*/ string repeat(lld rep, char inside) { char s[2] = "A"; s[0] = inside; return repeat(rep, s); } string row(lld width) { string ret = repeat(width, "A"); ret += repeat(width, "EC"); ret += 'E'; return ret; } string Lu_triangle(lld side); string Lu_D_triangle(lld side) { string ret = ""; ret += repeat(2, Lu_triangle(side/2)); ret += repeat(side/2, 'A'); string inside = ""; inside += repeat(side/2, 'E'); inside += repeat(side/2, "AC"); inside += 'A'; ret += repeat(side/2, inside); return ret; } // left up is the only side left string Lu_triangle(lld side) { if (side == 1) { return "C"; } if (side == 2) { return "CACEC"; } string ret = Lu_D_triangle(side/2); string inside = "C"; inside += repeat(side/2-1, "AC"); inside += repeat(side/2, 'E'); repeat(side/2, inside); ret += Lu_triangle(side/2); return ret; } string full_triangle(lld side) { if (side < 1) { return ""; } if (side == 1) { return "AEC"; } int pow = 1; while (pow * 2 <= side) { pow *= 2; } string ret = repeat(pow, "A"); // write_cut_trinagle_bottom(pow); lld row_lenght = side - pow; ret += repeat(pow, row(row_lenght)); ret += full_triangle(side - pow); ret += Lu_triangle(pow); return ret; } void solve(int test_number) { lld n; scanf("%lld", &n); cout << full_triangle(n) << endl; } int main() { int test_number = 1; // scanf("%d", &test_number); for (int test_id = 0; test_id < test_number; ++test_id) { solve(test_number); } } |