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
#include <iostream>
#include <vector>
#include <cmath>
typedef long long LLG;
const LLG MAXI = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    LLG k,n;
    cin >> n >> k;
    LLG pot = 1;
    int ct = 0;
    while(pot < MAXI && ct < n){
        pot*=2;
        ct++;
    }
    vector<int> ans;
    if(ct == n){
        ans.push_back((k-1)/(pot-1));
        if(ans.back() >= 3){
            cout<<"NIE\n";
            return 0;
        }
    }
    else ans.push_back(0);
    for(int i=1;i<n;i++){
        if(ct + i > n){
            while(k-(pot-1) >=1) k -= (pot-1);
            pot /=2;
            k--;
            if(k == 0) break;
            ans.push_back((k-1)/(pot-1));
        }
        else{
            k--;
            if(k == 0) break;
            ans.push_back(0);
        }
    }
    cout<<(char)(ans.front()+'a');
    char lastLetter = (ans.front()+'a');
    char thisLetter = 'a';
    for(int i=1;i<ans.size();i++){
        if(ans[i] == 0){
            if(lastLetter == 'a')
                thisLetter = 'b';
            else
                thisLetter = 'a';
        }
        if(ans[i] == 1){
            if(lastLetter == 'c')
                thisLetter = 'b';
            else
                thisLetter = 'c';
        }
        cout<<thisLetter;
        lastLetter = thisLetter;
    }
    cout<<endl;
}