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>

int nextChar(int prev, int high) {
	switch (prev) {
		case 0: return high ? 2 : 1;
		case 1: return high ? 2 : 0;
		case 2: return high ? 1 : 0;
	}
	return 666; // error
}

int main() {
	long long n, k;
	scanf("%lld %lld", &n, &k);
	long long max = n <= 60 ? ((1ll << n) - 1) * 3 : 0;
	if (--k >= max && n <= 60) {
		printf("NIE\n");
		return 0;
	}
	max /= 3;
	int prev = n <= 60 ? k / max : 0, curr, high;
	putchar(prev + 'a');
	k -= prev * max;
	while (k--) {
		max /= 2;
		high = n <= 60 ? k / max : 0;
		curr = nextChar(prev, high);
		putchar(curr + 'a');
		prev = curr;
		k -= n <= 60 ? high * max : 0;
		if (--n <= 60 && max == 0) {
			max = (1ll << n) - 1;
		}
	}
	printf("\n");
	return 0;
}