#include <iostream>
#include <cmath>
using namespace std;
char jednoZTrzech(unsigned long long n, unsigned long long& k)
{
if (n > 63)
{
return 'a';
}
for (char c = 'a'; c < 'd'; ++c)
{
if (k <= (1 << n) - 1)
{
return c;
}
k -= (1 << n) - 1;
}
// d jak DUPA
return 'd';
}
int main()
{
ios_base::sync_with_stdio(false);
unsigned long long n, k;
cin >> n >> k;
char last = jednoZTrzech(n, k);
if (last == 'd')
{
cout << "NIE" << endl;
return 0;
}
if (k > 0)
{
--n;
while (true)
{
#ifdef DEBUG
cerr << "last " << last << " n " << n << " k " << k << endl;
#endif
cout << last;
if (k == 1)
{
break;
}
--k;
if ((n > 63ull) || ((1ull << n) - 1ull >= k))
{
if (last == 'a')
{
last = 'b';
}
else
{
last = 'a';
}
--n;
continue;
}
else
{
if (last == 'c')
{
last = 'b';
}
else
{
last = 'c';
}
k -= ((1ull << n) - 1ull);
--n;
continue;
}
}
}
cout << endl;
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 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 84 | #include <iostream> #include <cmath> using namespace std; char jednoZTrzech(unsigned long long n, unsigned long long& k) { if (n > 63) { return 'a'; } for (char c = 'a'; c < 'd'; ++c) { if (k <= (1 << n) - 1) { return c; } k -= (1 << n) - 1; } // d jak DUPA return 'd'; } int main() { ios_base::sync_with_stdio(false); unsigned long long n, k; cin >> n >> k; char last = jednoZTrzech(n, k); if (last == 'd') { cout << "NIE" << endl; return 0; } if (k > 0) { --n; while (true) { #ifdef DEBUG cerr << "last " << last << " n " << n << " k " << k << endl; #endif cout << last; if (k == 1) { break; } --k; if ((n > 63ull) || ((1ull << n) - 1ull >= k)) { if (last == 'a') { last = 'b'; } else { last = 'a'; } --n; continue; } else { if (last == 'c') { last = 'b'; } else { last = 'c'; } k -= ((1ull << n) - 1ull); --n; continue; } } } cout << endl; return 0; } |
English