#include <iostream>
#include <limits>
#include <string>
using namespace std;
namespace {
constexpr auto inf = numeric_limits<long long>::max();
long long pow2(int n)
{
  if (n >= 63) return inf;
  return 1LL << n;
}
bool solve(string& res, int n, long long k, char last='\0')
{
  if (k == 0) return true;
  if (n == 0) return false;
  --k;
  auto cnt = pow2(n) - 1;
  for (char c: {'a', 'b', 'c'}) {
    if (c == last) continue;
    if (k < cnt) {
      res.push_back(c);
      return solve(res, n-1, k, c);
    }
    k -= cnt;
  }
  return false;
}
}
int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  long long k;
  cin >> n >> k;
  string res;
  if (solve(res, n, k)) cout << res << '\n';
  else cout << "NIE\n";
  return 0;
}
        | 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 | #include <iostream> #include <limits> #include <string> using namespace std; namespace { constexpr auto inf = numeric_limits<long long>::max(); long long pow2(int n) { if (n >= 63) return inf; return 1LL << n; } bool solve(string& res, int n, long long k, char last='\0') { if (k == 0) return true; if (n == 0) return false; --k; auto cnt = pow2(n) - 1; for (char c: {'a', 'b', 'c'}) { if (c == last) continue; if (k < cnt) { res.push_back(c); return solve(res, n-1, k, c); } k -= cnt; } return false; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n; long long k; cin >> n >> k; string res; if (solve(res, n, k)) cout << res << '\n'; else cout << "NIE\n"; return 0; } | 
 
            
         English
                    English