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
#include <iostream>
using namespace std;

int main(int argc, char** argv) 
{
	bool Search(int, int*, int, int, int);
	
	int fib[46];
	int t;
	const char Tak[] = "TAK\0", Nie[] = "NIE\0";
	fib[0] = 0;
	fib[1] = 1;

	for(int i = 2; fib[i - 1] < 1e9; i++)
	{
		fib[i] = fib[i - 2] + fib[i - 1];
	}
	
	cin >> t;
	for(int i = 1; i <= t; i++)
	{
		int num;
		cin >> num;
		
		if(num == 0)
		{
			cout << Tak << endl;
			continue;
		}
		for(int j = 1; j <= 45; j++)
		{
			if((float)num / (float)fib[j] == float(num / fib[j]))
			{
				if(Search(num / fib[j], fib, 0, 45, 22))
				{
					cout << Tak << endl;
					goto Unnest;
				}
			}
		}
		cout << Nie << endl;
		Unnest:
		;
	}
	return 0;
}

bool Search (int param, int fib[], int p, int q, int r)
{
	if(p == r || q == r)
		return false;
	if(param == fib[r])
		return true;
	if(param < fib[r])
		return Search(param, fib, p, r, (r - p) / 2 + p);
	if(param > fib[r])
		return Search(param, fib, r, q, (q - r) / 2 + r);
}