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
//package net.toomyem;

import java.math.BigInteger;
import java.util.Scanner;

public class slo {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        String result = slo(n, k - 1);
        System.out.println(result);
    }

    public static String slo(int n, int k) {
        String result = "";
        char lastV = ' ';
        char v = ' ';
        char[] t1 = {'a', 'b', 'c'};
        char[] t2 = {'b', 'c'};
        char[] t3 = {'a', 'c'};
        char[] t4 = {'a', 'b'};

        while (true) {
            BigInteger m = BigInteger.valueOf(2).pow(n).subtract(BigInteger.ONE);
            BigInteger p = BigInteger.valueOf(k).divide(m);
            BigInteger q = BigInteger.valueOf(k).mod(m);
            int pi = p.intValue();
            if (pi >= 3) {
                result = "NIE";
                break;
            }
            if (lastV == ' ') {
                v = t1[pi];
            } else if(lastV == 'a') {
                v = t2[pi];
            } else if(lastV == 'b') {
                v = t3[pi];
            } else if(lastV == 'c') {
                v = t4[pi];
            }
            result += v;
            if (q.intValue() == 0) break;
            k = q.intValue() - 1;
            n -= 1;
            lastV = v;
        }

        return result;
    }
}