#include <iostream> #include <vector> std::vector<long long> divisible; std::string repeat(long long n, std::string text){ std::string result=""; if(n==0||text=="") return result; if(n==1) return text; if(text.length()==1 && n<10) return std::to_string(n)+text; for(long long i=9;i>=2;i--){ if(n%i==0){ result=std::to_string(i)+'['+repeat(n/i,text)+']'; return result; } } long long n_copy=n; long long mn=1; while(n_copy>1000000LL) { n_copy /= 9; mn*=9; } mn*=divisible[n_copy]; result+=repeat(mn,text); result+=repeat(n-mn,text); //for(int i=0;i<n;i++){ // result+=text; //} return result; } std::string pane(long long n){ std::string row=repeat(n,"EC")+"E"+repeat(n,"A"); return repeat(n,row); } std::string draw(long long n){ std::string result=""; if (n<1) return result; if(n%2==0){ result+="C"; result+=repeat(n-1,"AC"); result+=repeat(n-1,"E"); return result+draw(n-1); }else{ result+="C"; result+=repeat(n-1,"AC"); result+=pane(n/2); result+=repeat(n/2,"E"); std::string half=draw(n/2); result+=repeat(2,half); return result; } } int main(){ divisible.emplace_back(0); divisible.emplace_back(1); long long last_divisible=1; for(long long i=2;i<=1000000;i++){ for(auto div:{2,3,5,7}){ if(i%div==0 && divisible[i/div]==i/div) last_divisible=i; } //if(last_divisible==i) // std::cerr<<i<<std::endl; divisible.emplace_back(last_divisible); } std::ios_base::sync_with_stdio(0); long long n; std::cin>>n; std::string res; res+=repeat(n,"A"); res+=repeat(n,"E"); res+=draw(n); std::cout<<res; }
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 | #include <iostream> #include <vector> std::vector<long long> divisible; std::string repeat(long long n, std::string text){ std::string result=""; if(n==0||text=="") return result; if(n==1) return text; if(text.length()==1 && n<10) return std::to_string(n)+text; for(long long i=9;i>=2;i--){ if(n%i==0){ result=std::to_string(i)+'['+repeat(n/i,text)+']'; return result; } } long long n_copy=n; long long mn=1; while(n_copy>1000000LL) { n_copy /= 9; mn*=9; } mn*=divisible[n_copy]; result+=repeat(mn,text); result+=repeat(n-mn,text); //for(int i=0;i<n;i++){ // result+=text; //} return result; } std::string pane(long long n){ std::string row=repeat(n,"EC")+"E"+repeat(n,"A"); return repeat(n,row); } std::string draw(long long n){ std::string result=""; if (n<1) return result; if(n%2==0){ result+="C"; result+=repeat(n-1,"AC"); result+=repeat(n-1,"E"); return result+draw(n-1); }else{ result+="C"; result+=repeat(n-1,"AC"); result+=pane(n/2); result+=repeat(n/2,"E"); std::string half=draw(n/2); result+=repeat(2,half); return result; } } int main(){ divisible.emplace_back(0); divisible.emplace_back(1); long long last_divisible=1; for(long long i=2;i<=1000000;i++){ for(auto div:{2,3,5,7}){ if(i%div==0 && divisible[i/div]==i/div) last_divisible=i; } //if(last_divisible==i) // std::cerr<<i<<std::endl; divisible.emplace_back(last_divisible); } std::ios_base::sync_with_stdio(0); long long n; std::cin>>n; std::string res; res+=repeat(n,"A"); res+=repeat(n,"E"); res+=draw(n); std::cout<<res; } |