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
#include <cstdio>

using namespace std;

int main() {
    int n;
    long long k,A[200];
    scanf("%d%lld",&n,&k);
    if ( k<=n ) {
        for ( int i=0; i<k; i++ ) printf("%c",'a'+(i%2));
        printf("\n"); return 0;
    }
    k -= n;
    long long a = 1;
    int ila=0;
    while ( a < k ) {
        k++;
        A[ila++] = a;
        a=a*2+1;
        if ( ila >= n-1 ) {
            if ( k+1<=a*3 ) break;
            printf("NIE\n");
            return 0;
        }
    }
    int b,l;
    if ( ila == n-1 ) {
        b = k/a;
        k -= a*b;
        printf("%c",'a'+b);
        l = b;
    } else {
        for ( int i=0; i<n-ila; i++ ) printf("%c",'a'+(i%2));
        l = (n-ila-1)%2;
    }
    for ( int i=ila-1; i>=0&&k; i-- ) {
        k--;
        a = A[i];
        int b = k/a;
        k -= a*b;
        if ( l<=b ) b++;
        l = b;
        printf("%c",'a'+b);
        l = b;
    }
    printf("\n");
    return 0;
}