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

using namespace std;
typedef unsigned long long ull;

ull tab[100];

ull pot(int i)
{
    if(i>60)
        i=60;
    return tab[i];
}

char zn(int a, char p)
{
    if(a==0)
    {
        if(p=='c')
            return 'a';
        if(p=='a')
            return 'b';
        if(p=='b')
            return 'a';
    }
    if(p=='c')
        return 'b';
    if(p=='b')
        return 'c';
    return 'c';
}

int main()
{
    ios_base::sync_with_stdio(0);
    ull n, k, i, x;
    char p;
    tab[0]=1;
    for(i=1; tab[i-1] < 1e18; i++)
    {
        tab[i]=tab[i-1]<<1;
        //cout << i << " " << tab[i] << "\n";
    }
    cin >> n >> k;
    x=pot(n)-1;
    if(k <= x)
    {
        cout << "a";
        p='a';
    }
    else if(k <= 2*x)
    {
        cout << "b";
        p='b';
        k-=x;
    }
    else if(k <= 3*x)
    {
        cout << "c";
        p='c';
        k-=2*x;
    }
    else
    {
        cout << "NIE";
        k=1;
    }
    n--;
    k--;
    while(k > 0)
    {
        k--;
        x=pot(n)-1;
        if(k < x)
            p = zn(0, p);
        else
        {
            k-=x;
            p = zn(1, p);
            //cout << "A";
        }
        cout << p;
        n--;
    }

    return 0;
}