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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// slo.cpp : Defines the entry point for the console application.
//

// #include "stdafx.h"


#include <stdio.h>
#include <string.h>


using namespace std;


typedef long long int lli;


static const lli MAX_N = 1000000;
static const lli MAX_K = 1000000000000000000;


static lli iN, iK;

static int iOutCnt;

static char aOut[MAX_N + 1];

static char cLast;


static lli GetSubtreeSize(lli i)
{
    return (((lli) 1) << (iN - i + 1)) - 1;
}


static inline void OutChar(char c)
{
    aOut[iOutCnt++] = c;

    cLast = c;
}


static void Solve()
{
    iOutCnt = 0;

    int iLevel = 1;

    int iPos = 0;

    cLast = 'x';

    lli iSumOfTreesOnThisLevel = 0;

    lli iTargetNumber = iK - 1;

    for (;;)
    {
        if (iLevel == 1 && iPos > 2)
        {
            strcpy(aOut, "NIE");
            iOutCnt = 3;
            return;
        }

        if (cLast != 'x' && iTargetNumber == 0 && iPos == 0)
        {
            return;
        }

        if (cLast == 'a' + iPos)
        {
            iPos++;
            continue;
        }

        if (iN - iLevel > 61 || iTargetNumber < iSumOfTreesOnThisLevel + GetSubtreeSize(iLevel))
        {
            OutChar('a' + iPos);

            if (iTargetNumber == 0)
            {
                return;
            }

            if (iN - iLevel > 61)
            {
                iTargetNumber--;
            }
            else
            {
                iTargetNumber -= iSumOfTreesOnThisLevel;
            }

            iSumOfTreesOnThisLevel = 1;
            iLevel++;
            iPos = 0;
            continue;
        }

        iSumOfTreesOnThisLevel += GetSubtreeSize(iLevel);
        iPos++;
    }
}


int main(int argc, char * argv[])
{
//    freopen("sample_input.txt",  "r", stdin);
//    freopen("sample_output.txt", "w", stdout);

    scanf("%lld", &iN);

    scanf("%lld", &iK);

    Solve();

    aOut[iOutCnt] = 0;

    printf("%s", aOut);

    return 0;
}