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
#include <stdio.h>

using namespace std;


char left_letter(char letter) {
   if (letter == 'a') return 'b';
   return 'a';
}
char right_letter(char letter) {
   if (letter == 'c') return 'b';
   return 'c';
}


int main() {
    int n;
    long long int k;
    scanf("%d", &n);
    scanf("%lld", &k);

    if (n > 60) {
      char prev_letter = 'a';
      while (n > 60 && k > 0) {
          printf("%c", prev_letter);
          prev_letter = left_letter(prev_letter);
          n--;
          k--;       
      }
      if (k > 0) {
        unsigned long long int left_words_num = ((unsigned long long int) 1 ) << n;
        while (k > 0) {
          printf("%c", prev_letter);
          left_words_num = (left_words_num >> 1);
          if (k == 1) { 
              k = 0;
          }
          else if (k <= left_words_num) {
            prev_letter = left_letter(prev_letter);
            k--;
          }
          else {
            prev_letter = right_letter(prev_letter);
            k = k - left_words_num;
          }
        }    
      }
      printf("\n");
    }
    else {
        unsigned long long int max_words = (((unsigned long long int) 1 ) << n ) - 1;
        char first_letter = 'a';
    
        while (k > max_words) {
          k = k - max_words;
          first_letter++;
          if (first_letter > 'c') {
            printf("NIE\n");
            return 0;
          }
        }
    
        char prev_letter = first_letter;
        long long int left_words_num = max_words + 1;
        while (k > 0) {
          printf("%c", prev_letter);
          left_words_num = (left_words_num >> 1);
          if (k == 1) { 
              k = 0;
          }
          else if (k <= left_words_num) {
            prev_letter = left_letter(prev_letter);
            k--;
          }
          else {
            prev_letter = right_letter(prev_letter);
            k = k - left_words_num;
          }
        }    
        printf("\n");
    }
    return 0;
}