#include<bits/stdc++.h>
using namespace std;
vector<char>kra = {'A', 'B', 'C', 'D', 'E', 'F'};
string skopiuj(long long ile, string x){
if(ile==0)
return "";
string odp;
if(ile%9>0){
if(ile%9>1){
odp.push_back('0'+ile%9);
if(x.size()>1)
odp.push_back('[');
}
// printf("%d[", ile%9);
odp+=x;
if(ile%9>1)
if(x.size()>1)
odp.push_back(']');
// printf("%s", x);
// printf("]");
ile-=ile%9;
}
if(ile>0){
odp.push_back('9');
odp.push_back('[');
// printf("9[");
odp+=skopiuj(ile/9, x);
// skopiuj(ile/9, x);
odp.push_back(']');
// printf("]");
}
return odp;
}
void wypstr(string a){
for(auto j: a)
printf("%c", j);
}
void powiel(long long ile, vector<int>zaw){
if(zaw.size()==0)return;
if(ile==0)return;
string x;
for(auto j: zaw)
x += 'A'+j%6;
if(ile==1){
wypstr(x);
// printf("%s", x);
return;
}
wypstr(skopiuj(ile, x));
// printf("%s", skopiuj(ile, x));
}
void wypelnij(long long n, int opcja)
{
if(n==1){
printf("%c%c", kra[(5+opcja)%6], kra[(1+opcja)%6]);
return;
}
if(n%2==0){
powiel(n-1, {5+opcja, 1+opcja});
printf("%c", kra[(5+opcja)%6]);
wypelnij(n-1, opcja+4);
powiel(n, {1+opcja});
return;
}
string x;
string pom="";
pom+=kra[(5+opcja)%6];
pom+=kra[(1+opcja)%6];
x = skopiuj(n-n/2-2, pom);
x+=kra[(5+opcja)%6];
string pom1=""; pom1+=kra[(3+opcja)%6];
x = x+skopiuj(n-n/2-2, pom1);
wypstr(skopiuj(n-n/2-1, x));
// printf("%s", skopiuj(n-n/2-1, x));
// printf("%lld[", n-n/2-1);
// powiel(n-n/2-2, {5+opcja, 1+opcja});
// printf("%c", kra[(5+opcja)%6]);
// powiel(n-n/2-2, {3+opcja});
// printf("]");
powiel(n/2, {5+opcja, 1+opcja});
powiel(n/2, {3+opcja, 1+opcja});
powiel(n/2, {5+opcja, 1+opcja});
printf("%c", kra[(5+opcja)%6]);
printf("2[");
wypelnij(n/2, opcja+4);
printf("]");
powiel(n, {1+opcja});
}
int main()
{
long long n;
scanf("%lld", &n);
wypelnij(n, 0);
powiel(n, {3+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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #include<bits/stdc++.h> using namespace std; vector<char>kra = {'A', 'B', 'C', 'D', 'E', 'F'}; string skopiuj(long long ile, string x){ if(ile==0) return ""; string odp; if(ile%9>0){ if(ile%9>1){ odp.push_back('0'+ile%9); if(x.size()>1) odp.push_back('['); } // printf("%d[", ile%9); odp+=x; if(ile%9>1) if(x.size()>1) odp.push_back(']'); // printf("%s", x); // printf("]"); ile-=ile%9; } if(ile>0){ odp.push_back('9'); odp.push_back('['); // printf("9["); odp+=skopiuj(ile/9, x); // skopiuj(ile/9, x); odp.push_back(']'); // printf("]"); } return odp; } void wypstr(string a){ for(auto j: a) printf("%c", j); } void powiel(long long ile, vector<int>zaw){ if(zaw.size()==0)return; if(ile==0)return; string x; for(auto j: zaw) x += 'A'+j%6; if(ile==1){ wypstr(x); // printf("%s", x); return; } wypstr(skopiuj(ile, x)); // printf("%s", skopiuj(ile, x)); } void wypelnij(long long n, int opcja) { if(n==1){ printf("%c%c", kra[(5+opcja)%6], kra[(1+opcja)%6]); return; } if(n%2==0){ powiel(n-1, {5+opcja, 1+opcja}); printf("%c", kra[(5+opcja)%6]); wypelnij(n-1, opcja+4); powiel(n, {1+opcja}); return; } string x; string pom=""; pom+=kra[(5+opcja)%6]; pom+=kra[(1+opcja)%6]; x = skopiuj(n-n/2-2, pom); x+=kra[(5+opcja)%6]; string pom1=""; pom1+=kra[(3+opcja)%6]; x = x+skopiuj(n-n/2-2, pom1); wypstr(skopiuj(n-n/2-1, x)); // printf("%s", skopiuj(n-n/2-1, x)); // printf("%lld[", n-n/2-1); // powiel(n-n/2-2, {5+opcja, 1+opcja}); // printf("%c", kra[(5+opcja)%6]); // powiel(n-n/2-2, {3+opcja}); // printf("]"); powiel(n/2, {5+opcja, 1+opcja}); powiel(n/2, {3+opcja, 1+opcja}); powiel(n/2, {5+opcja, 1+opcja}); printf("%c", kra[(5+opcja)%6]); printf("2["); wypelnij(n/2, opcja+4); printf("]"); powiel(n, {1+opcja}); } int main() { long long n; scanf("%lld", &n); wypelnij(n, 0); powiel(n, {3+0}); } |
English