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
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

vector<int> tiers;
vector<int> actions;
string tablica[6]={"A","B","C","D","E","F"};
string write(int ile, string text)
{
    if(ile==0)
    {
        return "";
    }
    if(ile==1)
    {
        return text;
    }
    if(actions[ile]>0)
    {
        if(text.length()==1 && ile<10)
        {
            return (to_string(actions[ile])+write(ile/actions[ile],text));
        }else
        {
            return (to_string(actions[ile])+"["+write(ile/actions[ile],text)+"]");
        }
    }
    if(actions[ile]<0)
    {
        return (write(ile+actions[ile],text) + write(-actions[ile],text));
    }
    return "Error";
}

string piramida(int n, int r)
{
    if (n==0) return"";
    if(n==1) return (tablica[(0+r)%6]+tablica[(4+r)%6]+tablica[(2+r)%6]);
    string odp="";
    int m=n/2;
    string pom="";
    //middle
    pom +=write(m,tablica[(0+r)%6]);
    pom+=write(m-1,tablica[(4+r)%6]+tablica[(2+r)%6]);
    pom+=tablica[(4+r)%6];
    odp+=write(n-m,pom);
    odp+=write(m,tablica[(0+r)%6]);
    //side
    odp+=piramida(n-m,r+2);
    //top
    odp+=write(m-1,tablica[(4+r)%6]+tablica[(2+r)%6]);
    odp+=tablica[(4+r)%6];
    odp+=piramida(m-1,r);
    odp+=write(n-m+1,tablica[(2+r)%6]);
    return odp;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    tiers.push_back(0);
    actions.push_back(0);
    tiers.push_back(1);
    actions.push_back(0);
    for(int i=2;i<=9;i++)
    {
        tiers.push_back(1);
        actions.push_back(i);
    }
    int minimum=0;
    int action=0;
    for(int i=10;i<=n;i++)
    {
        action=-1;
        minimum= tiers[i-1];
        for(int j=2;j<=9;j++)
        {
            if (tiers[i-j]<minimum)
            {
                minimum=tiers[i-j];
                action=-j;
            }
            if(i%j==0)
            {
                if(tiers[i/j]<=minimum)
                {
                    minimum=tiers[i/j];
                    action=j;
                }
            }
        }
        tiers.push_back(minimum+1);
        actions.push_back(action);
    }
    string odp=piramida(n,0);
    cout<<odp;
    return 0;
}