#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; string rep(string s,ll k) { string S=""; int d=0; while(k>0) { ll x=k%9; if(x>1) { S+=(x+'0'); if(sz(s)==1) S+=s; else S+="["+s+"]"; } if(x==1) S+=s; k/=9; if(k>0) { d++; S+="9["; } } while(d--) S+=']'; return S; } string Z[6]={"A","B","C","D","E","F"}; string rek(ll n) { if(n==0) return ""; if(n==1) return Z[1]+Z[3]+Z[5]; if(n%2==1) { return rep(Z[1],n)+rep(Z[3]+Z[5],n-1)+Z[3]+rek(n-1)+Z[5]; } string S=""; S+=rep(Z[1],n); S+=rep(rep(Z[3]+Z[5],n/2)+Z[3]+rep(Z[1],n/2),n/2); S+=rep(Z[3],n/2); if(n>=4) { S+=rep(rep(Z[5]+Z[1],n/2-1)+Z[5]+rep(Z[3]+Z[5],n/2-2)+Z[3]+rek(n/2-2)+Z[5],2); } else S+=Z[5]+Z[5]; return S; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; string ans=rek(n); cout<<ans<<endl; 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 | #include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; string rep(string s,ll k) { string S=""; int d=0; while(k>0) { ll x=k%9; if(x>1) { S+=(x+'0'); if(sz(s)==1) S+=s; else S+="["+s+"]"; } if(x==1) S+=s; k/=9; if(k>0) { d++; S+="9["; } } while(d--) S+=']'; return S; } string Z[6]={"A","B","C","D","E","F"}; string rek(ll n) { if(n==0) return ""; if(n==1) return Z[1]+Z[3]+Z[5]; if(n%2==1) { return rep(Z[1],n)+rep(Z[3]+Z[5],n-1)+Z[3]+rek(n-1)+Z[5]; } string S=""; S+=rep(Z[1],n); S+=rep(rep(Z[3]+Z[5],n/2)+Z[3]+rep(Z[1],n/2),n/2); S+=rep(Z[3],n/2); if(n>=4) { S+=rep(rep(Z[5]+Z[1],n/2-1)+Z[5]+rep(Z[3]+Z[5],n/2-2)+Z[3]+rek(n/2-2)+Z[5],2); } else S+=Z[5]+Z[5]; return S; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; string ans=rek(n); cout<<ans<<endl; return 0; } |