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
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author: patryk
 * @since: 06/05/14
 */
public class ilo {

    static int[] fibs  = new int[100000];

    private static int fib(int n) {
        int f = fibs[n];
        if (n != 0 && f == 0) {
            fibs[n] = fib(n-1) + fib(n-2);
        }
        return fibs[n];
    }


    public static void main(String...args) {
        Scanner s = new Scanner(System.in);

        fibs[0] = 0;
        fibs[1] = 1;


        int cases = s.nextInt();
        for (int c = 0; c < cases; ++c) {
            boolean found = false;
            long num = s.nextInt();
            int i = 1;
            if (num == 0) {
                System.out.println("TAK");
            }
            while (true) {
                int f = fib(i);
                if (f > num) {
                    found = false;
                    break;
                }
                int a = Arrays.binarySearch(fibs, 0, i+1, (int) num / f);
                if (a < 0) {
                    ++i;
                    continue;
                }
                int g = fibs[a];

                long fg = f * g;
                if (fg == num) {
                    System.out.println("TAK");
                    found = true;
                    break;
                } else {
                    ++i;
                }

            }
            if (!found) {
                System.out.println("NIE");
            }

        }
    }
}