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

using namespace std;
using lint = long long int;

const lint Inf = 1ll<<60;
const int nLim = 1000002;
lint UpToNWordsCounts[nLim] = { 2 };
pair<char, char> Nexts['d'];

int main()
{
	int n;
	lint k;
	scanf("%d%lld", &n, &k);
	
	Nexts['a'] = {'b', 'c'};
	Nexts['b'] = {'a', 'c'};
	Nexts['c'] = {'a', 'b'};
	
	for(int i = 1; i < n; ++i)
		UpToNWordsCounts[i] = min(Inf, 2*UpToNWordsCounts[i-1]);

	for(int i = 0; i < n; ++i)
		--UpToNWordsCounts[i];
		
	auto nWordCount = UpToNWordsCounts[--n];
	if(k > 3*nWordCount)
	{
		puts("NIE"); 
		return 0;
	}
	
	char prev = 'a';
	while(k > nWordCount)
		++prev, k -= nWordCount;
		
	putchar(prev);
		
	while(true)
	{
		if(--k == 0)
			break;
		else if(k <= UpToNWordsCounts[--n])
			putchar(prev = Nexts[prev].first);
		else
			putchar(prev = Nexts[prev].second), k -= UpToNWordsCounts[n];
	}
	
    return 0;
}