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
#include <iostream>
#include <string>

using ull = unsigned long long;

char diff(char rem, size_t upper)
{
  if (rem == 'a') {
    return "bc"[upper];
  } else if (rem == 'b') {
    return "ac"[upper];
  } else {
    return "ab"[upper];
  }
}

int main()
{
  std::ios::sync_with_stdio(false);
  
  ull n, k;
  std::cin >> n >> k;

  std::string result;
  result.reserve(n);
  
  if (n >= 60) {
    size_t idx = 0;
    while (n >= 60ull && k > 0ull) {
      result += "ab"[idx % 2];
      --k; --n; ++idx;
    }
  } else {
    ull s = (1ull << n) - 1ull;
    if (k <= s) {
      result += 'a';
      k -= 1;
    } else if (k <= 2ull * s) {
      result += 'b';
      k -= s;
    } else if (k <= 3ull * s) {
      result += 'c';
      k -= 2ull * s;
    } else {
      result += "NIE";
      k = 0ull;
    }
    --n;
  }

  while (k > 0 && n > 0) {
    char last = result.back();
    ull s = (1ull << n) - 1ull;
    if (k <= s) {
      result += diff(last, 0);
      --k;
    } else {
      result += diff(last, 1);
      k -= s + 1;
    }
    --n;
  }

  std::cout << result << std::endl;
  return 0;
}