#include <cstdio> using namespace std; long long int I64max; long long int n, k; long long int *L; int Lmax; char prev; void putLower() { switch(prev) { case 'a': printf("b"); prev='b'; break; case 'b': case 'c': printf("a"); prev='a'; break; } } void putHigher() { switch(prev) { case 'c': printf("b"); prev='b'; break; case 'b': ; case 'a': printf("c"); prev='c'; break; } } int main() { scanf("%d%d", &n, &k); I64max = 1; I64max <<= 61; L = new long long int [100]; L[0] = 1 ; for( int i=1 ; L[i-1]<I64max && i<=n-1 ; i++ ) { L[i] = 2*L[i-1]+1; Lmax = i; } if( n-1>Lmax || k<=L[n-1] ) { printf("a"); prev = 'a'; } else { k -= L[n-1]; if( k<=L[n-1] ) { printf("b"); prev = 'b'; } else { k -= L[n-1]; if( k<=L[n-1] ) { printf("c"); prev = 'c'; } else { printf("NIE\n"); return 0; } } } for( int i=n-1 ; i>0 ; i-- ) { if( k==1 ) { printf("\n"); return 0; } k--; if( i-1>Lmax ) { putLower(); } else if( k>L[i-1] ) { k -= L[i-1]; putHigher(); } else { putLower(); } } printf("\n"); 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 83 84 85 86 87 88 89 90 91 92 93 94 | #include <cstdio> using namespace std; long long int I64max; long long int n, k; long long int *L; int Lmax; char prev; void putLower() { switch(prev) { case 'a': printf("b"); prev='b'; break; case 'b': case 'c': printf("a"); prev='a'; break; } } void putHigher() { switch(prev) { case 'c': printf("b"); prev='b'; break; case 'b': ; case 'a': printf("c"); prev='c'; break; } } int main() { scanf("%d%d", &n, &k); I64max = 1; I64max <<= 61; L = new long long int [100]; L[0] = 1 ; for( int i=1 ; L[i-1]<I64max && i<=n-1 ; i++ ) { L[i] = 2*L[i-1]+1; Lmax = i; } if( n-1>Lmax || k<=L[n-1] ) { printf("a"); prev = 'a'; } else { k -= L[n-1]; if( k<=L[n-1] ) { printf("b"); prev = 'b'; } else { k -= L[n-1]; if( k<=L[n-1] ) { printf("c"); prev = 'c'; } else { printf("NIE\n"); return 0; } } } for( int i=n-1 ; i>0 ; i-- ) { if( k==1 ) { printf("\n"); return 0; } k--; if( i-1>Lmax ) { putLower(); } else if( k>L[i-1] ) { k -= L[i-1]; putHigher(); } else { putLower(); } } printf("\n"); return 0; } |