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

using namespace std;

int main()
{
	long long int s[100];
	s[0]=3;
	for (int i=1; i<100; i++)
		s[i] = 2*s[i-1];
	
	long long int k,n;
	char c;
	cin >> k >> n;
	long long int j=-1, sum=0;
	
	for (int i=0; i<k; i++)
		sum += s[i];
	
	if (sum < n)
	{
		cout << "NIE" << endl;
		return 0;
	}
	
	if (n<=sum/3)
		c = 'a';
	else if (n<=2*sum/3)
	{
		c = 'b';
		n -= sum/3;
	}
	else
	{
		c = 'c';
		n -= 2*sum/3;
	}
	sum /= 3;
	cout << c;
	if (n <= 1)
	{
		cout << endl;
		return 0;
	}
	
	
	while (sum>1)
	{
		if (n<=sum/2)
			c = (char)((c-'a'+1)%3+'a');
		else
		{
			c = (char)((c-'a'+2)%3+'a');
			n -= sum/2;
		}
		
		sum = (sum -1)/2;
		cout << c;
		
		if (n <= 1)
		{
			cout << endl;
			return 0;
		}
	}
	
	cout << endl;

}