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
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <time.h>
#include <queue>

typedef long long int64;

using namespace std;

int64 powers[61];

int main () {
	int64 pwr = 1;
	for (int i = 0; i <= 60; ++i) {
		powers[i] = pwr;
		pwr <<= 1;
	}
	int64 k, n;
	scanf("%lld %lld", &n, &k);
	--k;
	int letter1 = 0;
	int64 remaining = k;
	if (n <= 60) {
		int64 all_words = 3 * powers[n] - 3;
		if (k >= all_words) {
			printf("NIE\n");
			return 0;
		}
		letter1 = floor(3 * k / all_words);
		remaining = k - letter1 * (powers[n] - 1);
	}
	printf("%c", (char)('a' + letter1));
	int64 length_pwr = n;
	int prev = letter1;
	while (remaining) {
		--length_pwr;
		--remaining;
		int ch[2] = {prev ? 0 : 1, prev == 2 ? 1 : 2};
		int nch;
		if (length_pwr > 60) {
			nch = ch[0];
		}
		else if (remaining < powers[length_pwr] - 1) {
			nch = ch[0];
		}
		else {
			remaining -= powers[length_pwr] - 1;
			nch = ch[1];
		}
		printf("%c", (char)('a' + nch));
		prev = nch;
	}
	printf("\n");
	return 0;
}