Fibonacci string
Output of s [n] th and k-th bit string after ten
20 is calculated before the violence, more than 20, running dfs
#include <bits / STDC ++ H.> the using namespace STD; String S [ 1000 ]; typedef Long Long LL; LL n-, K; LL A [ 500 ]; String _s [ 100 ]; void DFS (LL K, int X, int len) /// k start position, x is this section which are spliced into the string, the bit k takes len { IF (X <= 20 is ) { for ( int I = - K- . 1 ; I <min (a [X], K + len . 1 ); I ++ ) { COUT << } S [X] [I]; return; } if(k>A[x-2]) { k-=A[x-2]; dfs(k,x-1,len); } else if(k+len<A[x-2]) { dfs(k,x-2,len); } else { dfs(k,x-2,A[x-2]-k+1); dfs(A[x-2]+1,x-1,len-A[x-2]+k-1); } } int main() { s[1]="COFFEE"; s[2]="CHICKEN"; A[1]=s[1].length(); A[2]=s[2].length(); for(int i=3; i<=20; i++) { s[i]=s[i-2]+s[i-1]; A[i]=A[i-2]+A[i-1]; } int t; scanf("%d",&t); for(int i=21; i<=57; i++) { A[i]=A[i-1]+A[i-2]; } while(t--) { scanf("%lld%lld",&n,&k); if(n<=20) { for(int i=k-1; i<min(k+9,A[n]); i++) { cout<<s[n][i]; } cout<<'\n'; } else if(n<=57) { dfs(k,n,10); cout<<'\n'; } else if(n>57) { if((n&1)) { dfs(k,57,10); cout<<'\n'; } else { dfs(k,56,10); cout<<'\n'; } } } }