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
// Karol Kosinski
#include <cstdio>
using namespace std;

typedef unsigned long long LG;
const LG INF = 2012345678901234567ULL;

inline LG threshold(int n)
{
        return (n <= 60) ? (1ULL << n) - 1 : INF;
}

char buffer[1000001];

int main()
{
        int n, ind = 0; LG k;
        scanf("%d%llu", &n, &k);

        LG mod = threshold(n);
        if (k <= mod)
        {
                buffer[ind] = 'a';
        }
        else if (k <= 2 * mod)
        {
                buffer[ind] = 'b';
                k -= mod;
        }
        else if (k <= 3 * mod)
        {
                buffer[ind] = 'c';
                k -= 2 * mod;
        }
        else
        {
                printf("NIE\n");
                return 0;
        }

        char letters[3][2] = { {'b','c'}, {'a','c'}, {'a','b'} };
        while (k > 1)
        {
                int prev = buffer[ind++] - 'a';
                if (k <= mod / 2 + 1)
                {
                        buffer[ind] = letters[prev][0];
                        --k;
                }
                else
                {
                        buffer[ind] = letters[prev][1];
                        k -= mod / 2 + 1;
                }
                mod = threshold(--n);
        }

        printf("%s\n", buffer);
        return 0;
}