#include <bits/stdc++.h>
using namespace std;
string licz(long long);
string liczBP(long long);
string mltp(long long t, string &p)
{
// cout << t << '\n';
string res = "";
if (t == 1)
return p;
if (t == 2 && p.size() == 1)
return p + p;
if (t == 3 && p.size() == 1)
return p + p + p;
if (t % 9)
{
res.push_back('0' + t % 9);
res += "[" + p + "]";
}
if (t >= 9)
res += "9[" + mltp(t / 9, p) + "]";
return res;
}
string A = "A", B = "B", C = "C", D = "D", E = "E", F = "F", CA = C + A;
string sch(long long n)
{
string schod = mltp(n, E) + mltp(n - 1, CA) + C;
return schod;
}
string liczBPIS(long long n)
{
string res = "";
res += mltp(n - 1, CA) + C;
res += liczBP(n - 1);
return res;
}
string liczBP(long long n)
{
if (n == 0)
return "";
if (n == 1)
{
return E + C;
}
string res;
if (n % 2)
{
res += sch(n);
n--;
}
assert(n % 2 == 0);
string scho = sch(n / 2);
res += mltp(n / 2, scho) + mltp(n / 2, E) + mltp(n / 2, A) + mltp(n / 2, E);
string t = liczBPIS(n / 2);
res += mltp(2, t);
// cout << n << ' ' << res.size() << '\n';
return res;
}
string licz(long long n)
{
if (n == 0)
return "";
if (n == 1)
return "AEC";
string res = mltp(n, A);
if (n % 2)
{
res += sch(n);
n--;
}
res += liczBP(n);
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
cout << licz(n) << '\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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> using namespace std; string licz(long long); string liczBP(long long); string mltp(long long t, string &p) { // cout << t << '\n'; string res = ""; if (t == 1) return p; if (t == 2 && p.size() == 1) return p + p; if (t == 3 && p.size() == 1) return p + p + p; if (t % 9) { res.push_back('0' + t % 9); res += "[" + p + "]"; } if (t >= 9) res += "9[" + mltp(t / 9, p) + "]"; return res; } string A = "A", B = "B", C = "C", D = "D", E = "E", F = "F", CA = C + A; string sch(long long n) { string schod = mltp(n, E) + mltp(n - 1, CA) + C; return schod; } string liczBPIS(long long n) { string res = ""; res += mltp(n - 1, CA) + C; res += liczBP(n - 1); return res; } string liczBP(long long n) { if (n == 0) return ""; if (n == 1) { return E + C; } string res; if (n % 2) { res += sch(n); n--; } assert(n % 2 == 0); string scho = sch(n / 2); res += mltp(n / 2, scho) + mltp(n / 2, E) + mltp(n / 2, A) + mltp(n / 2, E); string t = liczBPIS(n / 2); res += mltp(2, t); // cout << n << ' ' << res.size() << '\n'; return res; } string licz(long long n) { if (n == 0) return ""; if (n == 1) return "AEC"; string res = mltp(n, A); if (n % 2) { res += sch(n); n--; } res += liczBP(n); return res; } int main() { ios_base::sync_with_stdio(0); long long n; cin >> n; cout << licz(n) << '\n'; } |
English