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

const unsigned long long MAX = 1e18;
const unsigned long long MAX_LENGTH = 59;

unsigned long long N, K;

unsigned long long howMany(unsigned long long length)
{
	unsigned long long X = 1;
	return 3 * ((X << length) - 1); // 3 * (2^l - 1)
}

unsigned long long howManySubsequence(unsigned long long length)
{
	if (length == 0)
		return 0;

	if (length > MAX_LENGTH)
		return MAX + 1;

	unsigned long long X = 1;
	return (X << length) - 2;
}

void mapAndPrintCharacters(int option)
{
	printf(option == 1 ? "a" : ((option == 2) ? "b" : "c"));
}


int main()
{
	scanf("%llu %llu", &N, &K);

	if (N < MAX_LENGTH && howMany(N) < K) 
		printf("NIE\r\n");
	else
	{
		unsigned long long subSequenceCount = howManySubsequence(N--);
		unsigned long long perLetterCount = 1 + subSequenceCount;

		int characterToPrint = (K <= perLetterCount) ? 1 : ((K <= 2 * perLetterCount) ? 2 : 3);

		mapAndPrintCharacters(characterToPrint);

		if (K > (1 + (characterToPrint - 1)*perLetterCount))
		{
			K = K - (1 + (characterToPrint - 1)*perLetterCount);

			while (K > 0)
			{
				subSequenceCount = howManySubsequence(N--);
				perLetterCount = 1 + subSequenceCount;
				int firstCharacter = characterToPrint == 1 ? 2 : 1;
				int secondCharacter = characterToPrint == 3 ? 2 : 3;
				int characterIndex = ((K <= perLetterCount) ? 1 : 2);

				characterToPrint = ((characterIndex == 1) ? firstCharacter : secondCharacter);
				mapAndPrintCharacters(characterToPrint);

				if (K > (1 + (characterIndex - 1)*perLetterCount))
					K = K - (1 + (characterIndex - 1)*perLetterCount);
				else
					break;
			}
		}
	}
}