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
#include <iostream>
#include <vector>

const unsigned FIB_MAX = 1000000000;

inline unsigned NextFib(unsigned n1, unsigned n2) {
    return n1 + n2;
}

void FillFibonacci(std::vector<unsigned> &FibVec) {
    unsigned fibNum1 = 0, fibNum2 = 1;
    unsigned temp;

    FibVec.push_back(fibNum1);
    FibVec.push_back(fibNum2);

    while (fibNum2 < FIB_MAX) {
        FibVec.push_back(NextFib(fibNum1, fibNum2));

        temp = fibNum1;
        fibNum1 = fibNum2;
        fibNum2 += temp;
    }
}

bool checkTest(unsigned val, const std::vector<unsigned> &Fib) {
    unsigned product;
    for (unsigned i = 0; i < Fib.size(); ++i) {
        for (unsigned j = i; j < Fib.size(); ++j) {
            product = Fib[i] * Fib[j];

            if (product == val) {
                return true;
            } else if (product > val) {
                break;
            }
        }
    }

    return false;
}

int main()
{
    std::vector<unsigned> Fibonacci;
    FillFibonacci(Fibonacci);

    unsigned tests;
    std::cin >> tests;

    for (unsigned i = 0; i < tests; ++i) {
        unsigned currTest;
        std::cin >> currTest;

        std::cout << (checkTest(currTest, Fibonacci) ? "TAK\n" : "NIE\n");
    }

    return 0;
}