#include <stdio.h> #include <cmath> #include <iostream> using ll=long long; std::string parse(int amount, std::string expression){ if (amount == 0) return ""; if (amount == 1) return expression; if (amount < 10) return std::to_string(amount) + "[" + expression + "]"; for (int i = 9; i >= 2; i--){ if (amount%i == 0) return std::to_string(i) + "[" + parse(amount/i, expression) + "]"; } return expression + parse(amount-1, expression); } std::string stunningly_crude_pyramid(ll size){ // Left -> Top; left covered std::string res = ""; if (size == 0) return ""; res += parse(size, "A"); for (int i=size-1; i>0; i--){ res += parse(i, "EC") + "E" + parse(i, "A"); } res += "E"; return res; } std::string even_more_crude_pyramid(ll size){ //Top -> left; down, right covered std::string res = ""; if (size == 0) return ""; for (int i=size-1; i>0; i--){ res += parse(i, "CA") + "C" + parse(i, "E"); } res += "C"; return res; } std::string crude_pyramid(ll size){ //Right -> top; down, left covered if (size == 0) return ""; if (size == 1) return "E"; ll post_n = size-1; ll layers = pow(2, floor(log2(floor(pow(post_n, 0.5))))); ll single_layer_size = post_n/layers; std::string res = ""; ll level = 0; ll last_level_degree = 1; for (; level <= post_n - single_layer_size; level += single_layer_size){ std::string pipe = parse(post_n - level - single_layer_size, "EC") + "E" + parse(post_n - level - single_layer_size, "A"); last_level_degree = post_n - level - single_layer_size; res += parse(single_layer_size, pipe); } res += parse(last_level_degree, "EC"); res += parse(layers, even_more_crude_pyramid(single_layer_size)); res += parse(level, "EA") + "E"; res += stunningly_crude_pyramid(post_n-level); return res; } int main(){ ll n; scanf ("%lld", &n); ll layers = pow(2, floor(log2(floor(pow(n, 0.333333))))); ll single_layer_size = n/layers; ll dawn = n - single_layer_size*layers; std::string res; int level = dawn; res += parse(dawn, "C"); for (; level < n; level += single_layer_size){ std::string pipe = parse(level, "A") + parse(level, "CE") + "C"; res += parse(single_layer_size, pipe); } res += parse(n, "A"); res += parse(layers, crude_pyramid(single_layer_size)) + crude_pyramid(n - layers*single_layer_size); printf ("%s\n", res.c_str()); 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 | #include <stdio.h> #include <cmath> #include <iostream> using ll=long long; std::string parse(int amount, std::string expression){ if (amount == 0) return ""; if (amount == 1) return expression; if (amount < 10) return std::to_string(amount) + "[" + expression + "]"; for (int i = 9; i >= 2; i--){ if (amount%i == 0) return std::to_string(i) + "[" + parse(amount/i, expression) + "]"; } return expression + parse(amount-1, expression); } std::string stunningly_crude_pyramid(ll size){ // Left -> Top; left covered std::string res = ""; if (size == 0) return ""; res += parse(size, "A"); for (int i=size-1; i>0; i--){ res += parse(i, "EC") + "E" + parse(i, "A"); } res += "E"; return res; } std::string even_more_crude_pyramid(ll size){ //Top -> left; down, right covered std::string res = ""; if (size == 0) return ""; for (int i=size-1; i>0; i--){ res += parse(i, "CA") + "C" + parse(i, "E"); } res += "C"; return res; } std::string crude_pyramid(ll size){ //Right -> top; down, left covered if (size == 0) return ""; if (size == 1) return "E"; ll post_n = size-1; ll layers = pow(2, floor(log2(floor(pow(post_n, 0.5))))); ll single_layer_size = post_n/layers; std::string res = ""; ll level = 0; ll last_level_degree = 1; for (; level <= post_n - single_layer_size; level += single_layer_size){ std::string pipe = parse(post_n - level - single_layer_size, "EC") + "E" + parse(post_n - level - single_layer_size, "A"); last_level_degree = post_n - level - single_layer_size; res += parse(single_layer_size, pipe); } res += parse(last_level_degree, "EC"); res += parse(layers, even_more_crude_pyramid(single_layer_size)); res += parse(level, "EA") + "E"; res += stunningly_crude_pyramid(post_n-level); return res; } int main(){ ll n; scanf ("%lld", &n); ll layers = pow(2, floor(log2(floor(pow(n, 0.333333))))); ll single_layer_size = n/layers; ll dawn = n - single_layer_size*layers; std::string res; int level = dawn; res += parse(dawn, "C"); for (; level < n; level += single_layer_size){ std::string pipe = parse(level, "A") + parse(level, "CE") + "C"; res += parse(single_layer_size, pipe); } res += parse(n, "A"); res += parse(layers, crude_pyramid(single_layer_size)) + crude_pyramid(n - layers*single_layer_size); printf ("%s\n", res.c_str()); return 0;} |