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

public class ilo {

    private static Set<Integer> fibonacciDivisors;

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

        int count = scanner.nextInt();

        for (int i = 0; i < count; i++) {
            int number = scanner.nextInt();

            fibonacciDivisors(number);

            if (areTwoDivisorsFibonaccis(number)) {
                System.out.println("TAK");
            } else {
                System.out.println("NIE");
            }
        }
    }

    private static boolean areTwoDivisorsFibonaccis(int n) {
        int sqrt = (int) (Math.sqrt(n) + 1);

        for (int i : fibonacciDivisors) {
            if (i < sqrt) {
                if (fibonacciDivisors.contains(n / i)) {
                    return true;
                }
            }
        }

        return false;
    }

    private static void fibonacciDivisors(int number) {
        fibonacciDivisors = new LinkedHashSet<Integer>();
        fibonacciDivisors.add(1);

        int el1 = 1;
        int el2 = 1;
        int el3;

        while ((el3 = el2 + el1) <= number) {
            if (number % el3 == 0) {
                fibonacciDivisors.add(el3);
            }
            el1 = el2;
            el2 = el3;
        }
    }
}