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
#include <cstdio>
#include <cassert>
const int maxN = 1e6 + 10;
int i = 1;
long long k;
char t[maxN];

void f(int n) {
    if(k == 1) return;
    k--;
    t[i] = t[i - 1] == 'a' ? 'b' : 'a';
    if(n <= 60 && k > (1LL << n) - 1) {
        k -= (1LL << n) - 1;
        t[i]++;
        if(t[i] == t[i-1]) t[i]++;
    }
    i++;
    f(n - 1);
}

int main() {
    int n;
    scanf("%d%lld", &n, &k);
    t[0] = 'a';
    if(n <= 60) {
        if(k > (3LL << n) - 3) {
            printf("NIE\n");
            return 0;
        }
        while(k > (1LL << n) - 1) {
            t[0]++;
            k -= (1LL << n) - 1;
        }
    }
    f(n - 1);
    printf("%s\n", t);
}