#include<bits/stdc++.h> using namespace std; string toStr = "0123456789"; string getNormal(long long n); string getSpecial(long long n); pair<int,int> operator+(pair<int, int> a, pair<int, int> b){ pair<int, int> res = {a.first + b.first, a.second + b.second}; return res; } string strMul(string str, long long n){ if(n == 1)return str; if(n == 0)return ""; if(n <= 9 && str.length() == 1){ return toStr[n] + str; } for(long long i= 9; i >= 2; i--){ if(n % i == 0){ string ans = ""; ans += ('0' + i); ans += "["; ans += strMul(str, n/i); ans += "]"; return ans; } } long long a = n / 9; long long b = n % 9; return "9[" + strMul(str, a) + "]" + strMul(str, b); } string getDiamond(long long n){ string block = strMul("DF", n-1); block += "D"; block += strMul("B", n); return strMul(block, n); } string getSpecial(long long n){ if(n==1)return "A"; if(n==2)return "AEACA"; string ans = "A"; ans += getNormal(n-2); ans += strMul("EA", n-1); ans += strMul("CA", n-1); return ans; } string getNormal(long long n){ if(n==0)return ""; if(n == 1)return "AEC"; if(n % 2 == 1){ string ans = "A" + getNormal(n-1); ans += strMul("EA", n-1); ans += "E"; ans += strMul("C", n); return ans; } long long k = n/2; string ans; ans += strMul(getSpecial(k), 2); ans += strMul("E", k); ans += getDiamond(k); ans += strMul("F", k) + strMul("E", k) + strMul("C", n); return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*mt19937_64 random(time(NULL)); int cas; cin>>cas; int mx = 0; int mn = 1e7; long long a = 1e17; long long b = 1e18; while(cas--){ long long k = a + random()% b; //cout<<k<<"\n"; int val = getNormal(a + random()% b).length(); mx = max(mx, val); mn = min(mn, val); } cout<<mn<<" "<<mx<<"\n";*/ long long n; cin>>n; cout<<getNormal(n)<<"\n"; //cout<<strMul(str, n)<<"\n"; /*n = max(n, 20); vector<pair<int, int>> dp(n+1); dp[1] = {1, 0}; for(int i= 2; i <= 9; i++)dp[i] = {1, 1}; for(int i = 10; i <= n; i++){ dp[i] = {1e9, 1e9}; for(int j = 2; j <= 9; j++){ if(i % j == 0){ if(dp[i/j] + make_pair(0, 1) < dp[i]){ dp[i] = dp[i/j] + make_pair(0, 1); } } } for(int j = 2; j <= 9; j++){ if(dp[i-j] + make_pair(1, 0) < dp[i]){ dp[i] = dp[i-j] + make_pair(1, 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include<bits/stdc++.h> using namespace std; string toStr = "0123456789"; string getNormal(long long n); string getSpecial(long long n); pair<int,int> operator+(pair<int, int> a, pair<int, int> b){ pair<int, int> res = {a.first + b.first, a.second + b.second}; return res; } string strMul(string str, long long n){ if(n == 1)return str; if(n == 0)return ""; if(n <= 9 && str.length() == 1){ return toStr[n] + str; } for(long long i= 9; i >= 2; i--){ if(n % i == 0){ string ans = ""; ans += ('0' + i); ans += "["; ans += strMul(str, n/i); ans += "]"; return ans; } } long long a = n / 9; long long b = n % 9; return "9[" + strMul(str, a) + "]" + strMul(str, b); } string getDiamond(long long n){ string block = strMul("DF", n-1); block += "D"; block += strMul("B", n); return strMul(block, n); } string getSpecial(long long n){ if(n==1)return "A"; if(n==2)return "AEACA"; string ans = "A"; ans += getNormal(n-2); ans += strMul("EA", n-1); ans += strMul("CA", n-1); return ans; } string getNormal(long long n){ if(n==0)return ""; if(n == 1)return "AEC"; if(n % 2 == 1){ string ans = "A" + getNormal(n-1); ans += strMul("EA", n-1); ans += "E"; ans += strMul("C", n); return ans; } long long k = n/2; string ans; ans += strMul(getSpecial(k), 2); ans += strMul("E", k); ans += getDiamond(k); ans += strMul("F", k) + strMul("E", k) + strMul("C", n); return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*mt19937_64 random(time(NULL)); int cas; cin>>cas; int mx = 0; int mn = 1e7; long long a = 1e17; long long b = 1e18; while(cas--){ long long k = a + random()% b; //cout<<k<<"\n"; int val = getNormal(a + random()% b).length(); mx = max(mx, val); mn = min(mn, val); } cout<<mn<<" "<<mx<<"\n";*/ long long n; cin>>n; cout<<getNormal(n)<<"\n"; //cout<<strMul(str, n)<<"\n"; /*n = max(n, 20); vector<pair<int, int>> dp(n+1); dp[1] = {1, 0}; for(int i= 2; i <= 9; i++)dp[i] = {1, 1}; for(int i = 10; i <= n; i++){ dp[i] = {1e9, 1e9}; for(int j = 2; j <= 9; j++){ if(i % j == 0){ if(dp[i/j] + make_pair(0, 1) < dp[i]){ dp[i] = dp[i/j] + make_pair(0, 1); } } } for(int j = 2; j <= 9; j++){ if(dp[i-j] + make_pair(1, 0) < dp[i]){ dp[i] = dp[i-j] + make_pair(1, 0); } } }*/ } |