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
#include <string>
#include <unordered_set>

using namespace std;

int main() {
	int n, max = 0, idx, i;
	scanf("%d", &n);
	int arr[n];

	for (idx = 0; idx < n; ++idx) {
		scanf("%d", &arr[idx]);
		if (arr[idx] > max) {
			max = arr[idx];
		}
	}

	int fibs[50];
	fibs[0] = 2;
	fibs[1] = 3;

	unordered_set<int> fibsSet;
	fibsSet.insert(0);
	fibsSet.insert(1);
	fibsSet.insert(2);
	fibsSet.insert(3);

	idx = 1;
	while (true) {
		int next = fibs[idx] + fibs[idx - 1];
		if (next <= max) {
			fibs[++idx] = next;
			fibsSet.insert(next);
		} else {
			break;
		}
	}

	unordered_set<int>::iterator end = fibsSet.end();

	for (i = 0; i < n; ++i) {
		int val = arr[i];
		if (fibsSet.find(val) != end) {
			printf("%s\n", "TAK");
		} else {
			int greaterHalve = val / 2 + 1; // ;]
			idx = 0;

			while (true) {
				if (fibs[idx] >= greaterHalve) {
					printf("%s\n", "NIE");
					break;
				} else if (val % fibs[idx] == 0
						&& (fibsSet.find(val / fibs[idx]) != end)) {
					printf("%s\n", "TAK");
					break;
				} else {
					idx += 1;
				}
			}
		}
	}

	return 0;
}