#include <cstdio> long long T[3][3] = {1, 2, 0, 0, 2, 1, 0, 1, 2}; int main() { long long c, k, n; scanf ("%lld%lld", &n, &k); if (n < 60 && k > (3 * ((1LL << n) - 1))) // 59 printf ("NIE"); else for (c = 2; k > 0; n--) { c = T[c][(k - 1) / ((1LL << (n < 60 ? n : 60)) - 1)]; k = (k - 1) % ((1LL << (n < 60 ? n : 60)) - 1); putchar ('a' + c); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <cstdio> long long T[3][3] = {1, 2, 0, 0, 2, 1, 0, 1, 2}; int main() { long long c, k, n; scanf ("%lld%lld", &n, &k); if (n < 60 && k > (3 * ((1LL << n) - 1))) // 59 printf ("NIE"); else for (c = 2; k > 0; n--) { c = T[c][(k - 1) / ((1LL << (n < 60 ? n : 60)) - 1)]; k = (k - 1) % ((1LL << (n < 60 ? n : 60)) - 1); putchar ('a' + c); } return 0; } |