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
// Przemysław Szpakowicz

#include <bits/stdc++.h>

#define FOR(x, a, b) for(x = a; x < b; ++x)

const int MaxTextLength = 1000000;
const int Threshold = 60;

long long getChildrenAmountHavingTwoOptions(const int &charactersLeftAmount) {
    return (1LL << charactersLeftAmount) - 1;
}

char text[MaxTextLength];
int textLength = 0;

bool isSolution = true;

int charactersLeftAmount;
long long wordNumber;
char character;

void insertCharacter(const char &character) {
    text[textLength] = character;
    ++textLength;
}

void printSolution() {
    if(isSolution == false) {
        puts("NIE");
        return;
    }
    int characterIndex;
    FOR(characterIndex, 0, textLength)
        printf("%c", text[characterIndex]);
}

int main() {
    scanf("%d%lld", &charactersLeftAmount, &wordNumber);
    if(charactersLeftAmount <= Threshold) {
        long long childrenAmountForEachCharacter = getChildrenAmountHavingTwoOptions(charactersLeftAmount);
        if(wordNumber <= childrenAmountForEachCharacter)
            character = 'a';
        else if(wordNumber <= 2 * childrenAmountForEachCharacter)
            character = 'b',
            wordNumber -= childrenAmountForEachCharacter;
        else if(wordNumber <= 3 * childrenAmountForEachCharacter)
            character = 'c',
            wordNumber -= 2 * childrenAmountForEachCharacter;
        else
            isSolution = false;
    }
    else
        character = 'a';
    while(true) {
        insertCharacter(character);
        if(charactersLeftAmount == 1 || wordNumber == 1)
            break;
        --charactersLeftAmount;
        if(charactersLeftAmount <= Threshold) {
            long long childrenAmountForEachCharacter = getChildrenAmountHavingTwoOptions(charactersLeftAmount);
            if(wordNumber <= childrenAmountForEachCharacter + 1) {
                --wordNumber;
                if(character == 'a')
                    character = 'b';
                else
                    character = 'a';
            }
            else if(wordNumber <= 2 * childrenAmountForEachCharacter + 1) {
                wordNumber -= childrenAmountForEachCharacter + 1;
                if(character == 'c')
                    character = 'b';
                else
                    character = 'c';
            }
            else
                isSolution = false;
        }
        else {
            --wordNumber;
            if(character == 'a')
                character = 'b';
            else
                character = 'a';
        }
    }
    printSolution();
}