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

using namespace std;

typedef unsigned long long ull;

ull pow2[61];

char selectLetter(char prev, bool high)
{
    if (prev == 'a')
    {
        return high ? 'c' : 'b';
    }
    else if (prev == 'b')
    {
        return high ? 'c' : 'a';
    }
    else
    {
        return high ? 'b' : 'a';
    }
}

int main()
{
    ull n, k;
    cin >> n >> k;

    string result = "";

    pow2[0] = 1;
    for (int i = 1; i < 61; i++)
    {
        pow2[i] = pow2[i - 1] * 2;
    }

    if (n <= 60 && k > 3 * (pow2[n] - 1))
    {
        cout << "NIE" << endl;
    }
    else
    {
        if (n > 60 || k <= pow2[n] - 1)
            result = "a";
        else if (k <= (pow2[n] - 1) * 2)
        {
            result = "b";
            k -= pow2[n] - 1;
        }
        else
        {
            result = "c";
            k -= (pow2[n] - 1) * 2;
        }
        n--;

        while (k > 1)
        {
            k--;
            if (n >60 || k <= pow2[n] - 1)
            {
                result.push_back(selectLetter(result[result.length() - 1], false));
            }
            else
            {
                result.push_back(selectLetter(result[result.length() - 1], true));
                k -= pow2[n] - 1;
            }
            n--;
        }

        cout << result << endl;
    }

    return 0;
}