#include<string> #include<stdio.h> #include<iostream> #include<set> #include<vector> #include<algorithm> #include<queue> #include<bitset> #define ll long long #define pb push_back #define sc scanf #define pr printf #define f first #define s second #define mp make_pair #define lb lower_bound using namespace std; char t[1000000]; void ws(int x,char c){ if(t[x-1]<=c)c++; t[x]=c; return; } int main (){ int n; ll k; scanf("%d%lld",&n,&k); ll p; if(n<=60){ p=(1<<n)-1; if(k<=p){ k-=1; t[0]='a'; } else if(k<=p+p){ k-=p+1; t[0]='b'; } else if(k<=p+p+p){ k-=p+p+1; t[0]='c'; } else{ printf("NIE"); return 0; } } else{ k-=1; t[0]='a'; } n--; int x=1; //printf("tu"); while(n>0){ if(k<=0)break; if(n>=60)p=((ll)(1))<<60; else p=((ll)(1))<<n; if(k>=p){ k-=p; ws(x,'b'); x++; } else{ ws(x,'a'); k-=1; x++; } n--; } for(int i=0;i<x;i++)printf("%c",t[i]); 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 76 77 | #include<string> #include<stdio.h> #include<iostream> #include<set> #include<vector> #include<algorithm> #include<queue> #include<bitset> #define ll long long #define pb push_back #define sc scanf #define pr printf #define f first #define s second #define mp make_pair #define lb lower_bound using namespace std; char t[1000000]; void ws(int x,char c){ if(t[x-1]<=c)c++; t[x]=c; return; } int main (){ int n; ll k; scanf("%d%lld",&n,&k); ll p; if(n<=60){ p=(1<<n)-1; if(k<=p){ k-=1; t[0]='a'; } else if(k<=p+p){ k-=p+1; t[0]='b'; } else if(k<=p+p+p){ k-=p+p+1; t[0]='c'; } else{ printf("NIE"); return 0; } } else{ k-=1; t[0]='a'; } n--; int x=1; //printf("tu"); while(n>0){ if(k<=0)break; if(n>=60)p=((ll)(1))<<60; else p=((ll)(1))<<n; if(k>=p){ k-=p; ws(x,'b'); x++; } else{ ws(x,'a'); k-=1; x++; } n--; } for(int i=0;i<x;i++)printf("%c",t[i]); return 0; } |