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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	int t;
	cin >> t;
	int max = 0;
	vector<int> n(t);
	for (int i = 0; i < t; ++i)
	{
		cin >> n[i];
		if (n[i] > max) max = n[i];
	}
	vector<int> fib;
	if (max != 0)
	{
		fib.push_back(1);
		fib.push_back(1);
		for (int i = 2; fib[i - 2] + fib[i - 1] <= max; ++i) fib.push_back(fib[i - 2] + fib[i - 1]);
	}
	for (int i = 0; i < t; ++i)
	{
		if (n[i] != 0)
		{
			int i_dz = 1;
			vector<int> dzielniki;
			while (fib[i_dz] <= n[i])
			{
				if (n[i] % fib[i_dz] == 0) dzielniki.push_back(fib[i_dz]);
				if (i_dz == fib.size() - 1) break;
				++i_dz;
			}
			int j;
			for (j = 0; j < dzielniki.size(); ++j)
			{
				int c1 = fib[dzielniki[j]], c2 = n[i] / c1;
				int l = 0, p = fib.size() - 1, s;
				while (l <= p)
				{
					s = (l + p) / 2;
					if (fib[s] == c2) break;
					if (fib[s] < c2) l = s + 1;
					else p = s - 1;
				}
				if (fib[s] == c2)
				{
					cout << "TAK\n";
					break;
				}
			}
			if (j == dzielniki.size()) cout << "NIE\n";
		}
		else cout << "TAK\n";
	}
	return 0;
}