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
#include <cstdio>
#include <cstdlib>

// this is enough for n <= 10^9
const int FIB_BUFFER_LEN = 45;
int fib_buffer[FIB_BUFFER_LEN];


void prepare_fib_buffer(int* fib_buffer, size_t len) {
    int fib_a = 0, fib_b = 1, tmp = 0;

    if (len >= 1) {
        fib_buffer[0] = fib_a;
    }
    if (len >= 2) {
        fib_buffer[1] = fib_b;
    }
    for (size_t i = 2; i < len; ++i)
    {
        tmp = fib_b + fib_a;
        fib_buffer[i] = tmp;
        fib_a = fib_b;
        fib_b = tmp;
    }
}


bool test_fib(int n) {
    for (size_t i = 0; i < FIB_BUFFER_LEN; ++i) {
        if (n == fib_buffer[i]) {
            return true;
        }
    }

    return false;
}


bool test_fib_product(int n) {
    if (n == 0 || n == 1) {
        // trivial cases, nothing to do here.
        return true;
    }

    // omitting 0,1,1
    for (size_t i = 3; i < FIB_BUFFER_LEN; ++i) {
        if (n % fib_buffer[i] == 0) {
            if (test_fib(n / fib_buffer[i])) {
                return true;
            }
        }
    }

    return false;
}

int main() {
    int t = 0, n = 0;

    prepare_fib_buffer(fib_buffer, FIB_BUFFER_LEN);

    scanf("%d", &t);
    for (int i = 0; i < t; ++i) {
        scanf("%d", &n);
        if (test_fib_product(n)) {
            printf("TAK\n");
        }
        else {
            printf("NIE\n");
        }
    }
}