#include <bits/stdc++.h>
using namespace std;
long long n,lst;
string solve(long long n, long long f) {
string ans="";
if (n==1) {
if (f>0) ans+=to_string(f+1);
ans+="FB";
lst=1;
return ans;
}
long long up=max(1LL,n/4);
ans+=solve(up,f+n-up);
if (lst>0) {
if (lst>1) ans+=to_string(lst);
ans+="D";
}
string pref="";
if (up==2) pref="BF"; else if (up==3) pref="BFBF"; else if (up>3) {
pref+=to_string(up-1);
pref+="[BF]";
}
pref+="B";
string suf="";
if (up>1) suf+=to_string(up);
suf+="D";
if (n-up==1) ans+=pref; else if (n-up==2) ans+=pref+suf+pref; else {
ans+=to_string(n-up-1);
ans+="[";
ans+=pref;
ans+=suf;
ans+="]";
ans+=pref;
}
ans+=solve(n-up,0);
lst+=suf.length();
return ans;
}
int main() {
scanf("%lld",&n);
string res=solve(n,0);
if (lst>0) {
if (lst>1) res+=to_string(lst);
res+="D";
}
puts(res.c_str());
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 | #include <bits/stdc++.h> using namespace std; long long n,lst; string solve(long long n, long long f) { string ans=""; if (n==1) { if (f>0) ans+=to_string(f+1); ans+="FB"; lst=1; return ans; } long long up=max(1LL,n/4); ans+=solve(up,f+n-up); if (lst>0) { if (lst>1) ans+=to_string(lst); ans+="D"; } string pref=""; if (up==2) pref="BF"; else if (up==3) pref="BFBF"; else if (up>3) { pref+=to_string(up-1); pref+="[BF]"; } pref+="B"; string suf=""; if (up>1) suf+=to_string(up); suf+="D"; if (n-up==1) ans+=pref; else if (n-up==2) ans+=pref+suf+pref; else { ans+=to_string(n-up-1); ans+="["; ans+=pref; ans+=suf; ans+="]"; ans+=pref; } ans+=solve(n-up,0); lst+=suf.length(); return ans; } int main() { scanf("%lld",&n); string res=solve(n,0); if (lst>0) { if (lst>1) res+=to_string(lst); res+="D"; } puts(res.c_str()); return 0; } |
English