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

using namespace std;

int n;
unsigned long long k;

#define FIRST(c) (c=='a' ? 'b' : 'a')
#define SECOND(c) (c=='c' ? 'b' : 'c')

void calc_old(int n, unsigned long long k, char c)
{
    cout << c;
//    cout << n << " " << k << " " << c << endl;
    if(k==1)
        return;
    if(n>63)
        calc_old(n-1, k-1, FIRST(c));
    else
    {
        unsigned long long cmp = (0x1LL<<n);
//        cout << k << (k>cmp ? ">" : "<=") << cmp << endl;
        if(k>cmp)
            calc_old(n-1, k-cmp, SECOND(c));
        else
            calc_old(n-1, k-1, FIRST(c));
    }
}
void calc(int n, unsigned long long k, char c)
{
    cout << c;
    while(k>1)
    {
//cout << n << " " << k << " " << c << endl;
        if(n>63)
        {
            --k;
            c = FIRST(c);
        }
        else
        {
            unsigned long long cmp = (0x1LL<<n);
//        cout << k << (k>cmp ? ">" : "<=") << cmp << endl;
            if(k>cmp)
            {
                k -= cmp;
                c = SECOND(c);
            }
            else
            {
                --k;
                c = FIRST(c);
            }
        }
        --n;
        cout << c;
    }
}


int main() {
    cin>>n>>k;
    if(n<63) {
        unsigned long long onetree = (0x1LL<<n)-1;
        if(3*onetree < k)
        {
            cout << "NIE";
            return 0;
        }
        if(k<=onetree)
            calc(n-1, k, 'a');
        else if(k<=(onetree+onetree))
            calc(n-1, k-onetree, 'b');
        else
            calc(n-1, k-onetree-onetree, 'c');
    }
    else
        calc(n-1, k, 'a');

    return 0;
}