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

using namespace std;

int n;
long long k;
long long tab[105];
long long sum[105];
long long pot[105];
long long spo[105];

vector <char> v;

int main ()
{
	scanf("%d%lld", &n, &k);
	tab[1] = sum[1] = 3;
	for (int i = 2; i < 62; ++i) tab[i] = 2 * tab[i - 1];
	for (int i = 2; i < 62; ++i) sum[i] = sum[i - 1] + tab[i];
	if ((n < 60) && (k > sum[n]))
	{
		printf("NIE\n");
		return 0;
	}
	if (n < 62)
	{
		if (k <= sum[n] / 3) v.push_back('a');
		else if (k <= (sum[n] / 3) * 2)
		{
			v.push_back('b');
			k -= sum[n] / 3;
		}
		else
		{
			v.push_back('c');
			k -= (sum[n] / 3) * 2;
		}
		n--;
	}
	if (n > 60)
	{
		v.push_back('a');
		n--;
	}
	pot[0] = spo[0] = 1;
	for (int i = 1; i < 62; ++i) pot[i] = 2 * pot[i - 1];
	for (int i = 1; i < 62; ++i) spo[i] = spo[i - 1] + pot[i];
	while (n > 60)
	{
		if (k == 1)
		{
			for (int i = 0; i < v.size(); ++i) printf("%c", v[i]);
			printf("\n");
			return 0;
		}
		k--;
		n--;
		if (v.back() == 'a') v.push_back('b');
		else v.push_back('a');
	}
	while (k != 1)
	{
		k--;
		if (k <= (spo[n] - 1) / 2)
		{
			if (v.back() == 'a') v.push_back('b');
			else v.push_back('a');
		}
		else
		{
			if (v.back() == 'c') v.push_back('b');
			else v.push_back('c');
			k -= (spo[n] - 1) / 2;
		}
		n--;
	}
	for (int i = 0; i < v.size(); ++i) printf("%c", v[i]);
	printf("\n");
	return 0;
}