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
#include <stdio.h>
#include <math.h>

char next(const char current, bool stay)
{
	switch (current)
	{
		case 'a':
			return stay ? 'b' : 'c';
		case 'b':
			return stay ? 'a' : 'c';
		case 'c':
			return stay ? 'a' : 'b';
	}
	return 0;
}

int main(int, char **)
{
	int n;
	long long int k;
	scanf("%d %lld\n", &n, &k);

	char *data = new char[n + 1];
	for (int i=0; i<n; ++i)
	{
		if (k-- == 0)
		{
			break;
		}
		if (n - i > 61)
		{
			data[i] = i == 0 ? 'a' : next(data[i-1], true);
		}
		else
		{
			const long long int count = pow(2.0, n - i) - 1.0;
			if (i == 0)
			{
				if (k >= count * 3)
				{
					printf("NIE\n");
					return 0;
				}
				data[i] = 'a' + k / count;
			}
			else
			{
				if (k >= count * 2)
				{
					printf("NIE\n");
					return 0;
				}
				data[i] = next(data[i-1], k < count);
			}
			k = k % count;
		}
	}

	printf("%s\n", data);
	delete [] data;
	return 0;
}