#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937_64 mrand(1); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head ll n; string multiple(ll n, string s) { string ret = ""; int size = s.size(); bool ok = false; while (n) { if (ret.size()) ret = "9[" + ret + "]"; if (n % 9 != 0 && n % 9 != 1) { if (size == 1) ret += to_string(n % 9) + s; else ret += to_string(n % 9) + "[" + s + "]"; } else if (n % 9 == 1) ret += s; n /= 9; } return ret; } string rec(ll n) { if (n == 0) return ""; if (n == 1) return "AEC"; string ret = ""; //prawo ret += multiple(n / 2, "A"); ret += rec(n - n / 2); //środek ret += multiple(n / 2 - 1, multiple(n - n / 2 - 1, "EA") + "E" + multiple(n - n / 2, "C")); ret += multiple(n - n / 2 - 1, "EA") + "E"; //góra ret += rec(n / 2); ret += multiple(n - n / 2, "C"); return ret; } int main() { scanf("%lld", &n); printf("%s", rec(n).c_str()); //printf("%d\n", rec(n).size()); }
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 | #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937_64 mrand(1); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head ll n; string multiple(ll n, string s) { string ret = ""; int size = s.size(); bool ok = false; while (n) { if (ret.size()) ret = "9[" + ret + "]"; if (n % 9 != 0 && n % 9 != 1) { if (size == 1) ret += to_string(n % 9) + s; else ret += to_string(n % 9) + "[" + s + "]"; } else if (n % 9 == 1) ret += s; n /= 9; } return ret; } string rec(ll n) { if (n == 0) return ""; if (n == 1) return "AEC"; string ret = ""; //prawo ret += multiple(n / 2, "A"); ret += rec(n - n / 2); //środek ret += multiple(n / 2 - 1, multiple(n - n / 2 - 1, "EA") + "E" + multiple(n - n / 2, "C")); ret += multiple(n - n / 2 - 1, "EA") + "E"; //góra ret += rec(n / 2); ret += multiple(n - n / 2, "C"); return ret; } int main() { scanf("%lld", &n); printf("%s", rec(n).c_str()); //printf("%d\n", rec(n).size()); } |