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

void fib(int*& f, const int& e) {
    f = new int [e];
    f[0] = 0;
    f[1] = 1;
    int i = 1;
    while (++i < e)
        f[i] = f[i - 1] + f[i - 2];
}

bool binarySearch(int*& f, const int& i, const int& e, const int& what) {
    int l = i, r = e - 1, mid;
    while (l < r) {
        mid = (l + r) / 2;
        if (f[mid] < what)
            l = mid + 1;
        else
            r = mid;
    }
    return (f[l] == what);
}

void read(int*& f, int& num, const int& e) {
    scanf("%d", &num);
    int test;
    for (int i = 0; i < num; ++i) {
        scanf("%d", &test);
        if (test == 0) {
            printf("TAK\n");
            continue;
        }
        for (int i = 1; i < e; ++i)
            if (test % f[i] == 0 && binarySearch(f, i, e, test / f[i])) {
                printf("TAK\n");
                goto go;
            }
            printf("NIE\n");
            go:;
    }
}

int main() {
    int num = 0, *f = NULL;
    const int e = 46;
    fib(f, e);
    read(f, num, e);
    return 0;
}