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
#include <bits/stdc++.h>

typedef long long ll;

const int N = 1000000 + 10;

ll pw[N], k;

int main() {
  int n;
  scanf("%d%lld", &n, &k);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pw[i] = pw[i - 1] * 2;
    if (pw[i] > k) pw[i] = k * 2;
  }
  for (int i = 1; i <= n; ++i) {
    pw[i] += pw[i - 1];
    if (pw[i] > k) pw[i] = k * 2;
  }
  if (3 * pw[n - 1] < k) puts("NIE");
  else {
    char prev = 'z';
    for (int i = 1; i <= n && k; ++i) {
      for (char c = 'a'; c <= 'c'; ++c) {
        if (c == prev) continue;
        if (k <= pw[n - i]) {
          prev = c;
          break;
        } else {
          k -= pw[n - i];
        }
      }
      putchar(prev);
      k -= 1;
    }
    puts("");
  }
  return 0;
}