#include <iostream> #include <cstdio> using namespace std; long long n,k; char startchar = 'a'; long long pow2(int n) { long long x = 1; while(n)x*=2,n--; return x; } int main() { scanf("%lld %lld",&n,&k); long long p = 1; for(int i=1;i<=n;i++) { if(p>k)break; p*=2; } while(k>=p) { k-=p-1; startchar++; if(startchar>='d')break; } if(startchar>='d') { printf("NIE"); return 0; } long long w=1; long long m = n-1; long long x = -1; while(w!=k) { //cout<<w<<' '<<x<<' '; putchar(startchar); //cout<<endl; char c_l,c_r; if(startchar == 'a') c_l = 'b', c_r = 'c'; else if(startchar == 'b') c_l = 'a', c_r = 'c'; else if(startchar == 'c') c_l = 'a', c_r = 'b'; if(m>60) { w++; startchar = c_l; m--; } else { if(x == -1)x = pow2(m); if(k >= w + x)w += x, startchar = c_r; else w++, startchar = c_l; x/=2; } } putchar(startchar); 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 78 79 80 81 82 | #include <iostream> #include <cstdio> using namespace std; long long n,k; char startchar = 'a'; long long pow2(int n) { long long x = 1; while(n)x*=2,n--; return x; } int main() { scanf("%lld %lld",&n,&k); long long p = 1; for(int i=1;i<=n;i++) { if(p>k)break; p*=2; } while(k>=p) { k-=p-1; startchar++; if(startchar>='d')break; } if(startchar>='d') { printf("NIE"); return 0; } long long w=1; long long m = n-1; long long x = -1; while(w!=k) { //cout<<w<<' '<<x<<' '; putchar(startchar); //cout<<endl; char c_l,c_r; if(startchar == 'a') c_l = 'b', c_r = 'c'; else if(startchar == 'b') c_l = 'a', c_r = 'c'; else if(startchar == 'c') c_l = 'a', c_r = 'b'; if(m>60) { w++; startchar = c_l; m--; } else { if(x == -1)x = pow2(m); if(k >= w + x)w += x, startchar = c_r; else w++, startchar = c_l; x/=2; } } putchar(startchar); return 0; } |