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
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define FIB_SIZE 43
#define MAX_NUM 1000000000

inline int generate_fib(int f[])
{
	// This function skips first two elements - 0 and 1
	int counter = 0;
	int fib_p=1, fib_n=1, tmp;

	while(fib_n <= MAX_NUM)
	{
		//printf("%d ", fib_n);
		f[counter] = fib_n;
		//printf("%d ", fib_p);
		tmp = fib_n;
		fib_n += fib_p;
		fib_p = tmp;
		counter++;
	}

	return counter;
}

inline int check_num(int f[], int x)
{
	if(x == 0)
		return 1;
	else
		for(int j=0; j<FIB_SIZE; j++)
			if(x == f[j])
				return 1;
			else if(x%f[j] != 0)
				continue;
			else if(f[j] <= sqrt((float)MAX_NUM))
				for(int k=j; k<FIB_SIZE; k++)
					if(f[j]*f[k] == x)
						return 1;
	// Return default answer
	return 0;
}

int main()
{
	int n = 0;
	int f[FIB_SIZE];

	generate_fib(f);
	
	// Main loop
	scanf("%d", &n);

	for(int i=0; i<n; i++)
	{
		int x;
		scanf("%d", &x);
	
		if(check_num(f, x))
			printf("TAK\n");
		else
			printf("NIE\n");
	}

	return 0;
}