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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <vector>
#include <cmath>

typedef unsigned long long ULL;

inline ULL calcGroupSize(ULL n)
{
	return (2ull << (n - 1)) - 1;
}

int main()
{
	//ULL mainK = 0;
	//while (mainK <= 21) {
		std::ios::sync_with_stdio(false);
		const int nThreshold = 62;
		ULL n = 3, k;
		char last = '\0';
		bool first = true;
		std::vector<char> result;

		std::cin >> n >> k;

		if (n <= nThreshold && 3 * calcGroupSize(n) < k)
		{
			std::cout << "NIE";
			return 0;
		}

		result.reserve(n);

		if(n > nThreshold)
		{
			for(int i = 0; i < n - nThreshold; ++i)
			{
				last = last == 'b' || last == '\0' ? 'a' : 'b';
				result.push_back(last);
			}

			first = false;
			k = k - (n - nThreshold);
			n = nThreshold;
		}

		if (first)
		{
			const ULL groupSize = calcGroupSize(n);
			if (k <= groupSize)
			{
				last = 'a';
				--k;
			}
			else if (k > groupSize && k <= 2 * groupSize)
			{

				last = 'b';
				k -= groupSize + 1;
			}
			else
			{
				last = 'c';
				k -= 2 * groupSize + 1;
			}
			result.push_back(last);
			--n;
		}

		while (n > 0 && k != 0)
		{
			
			const ULL groupSize = calcGroupSize(n);
			if (k <= groupSize)
			{
				last = last == 'a' ? 'b' :
					last == 'b' ? 'a' : 'a';
				--k;
			}
			else if (k > groupSize && k <= 2 * groupSize)
			{
				last = last == 'a' ? 'c' :
					last == 'b' ? 'c' : 'b';
				k -= groupSize + 1;
			}

			result.push_back(last);
			--n;
		}

		for (auto c : result)
			std::cout << c;
		std::cout << std::endl;
		//std::cin.ignore();
		//std::cin.get();
	//}
}