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
#include <cstdio>
#include <cmath>

int main(int argc, char *argv[]) {
	auto isPrime = [](long long n) {
		if (n == 2) {
			return true;
		}
		if (n % 2 == 0) {
			return false;
		}
		int limit = std::sqrt(n);
		for (int c = 3; c <= limit; c += 2) {
			if (n % c == 0) {
				return false;
			}
		}
		return true;
	};

	bool ret = false;
	long long right, left = 0, prev = 0, multi = 1;

	scanf("%lli", &right);

	while (right > 0) {
		if (left != prev) {
			if (isPrime(right) && isPrime(left)) {
				//printf("%lli %lli\n", right, left);
				ret = true;
				break;
			}
		}

		prev = left;
		left += multi * (right % 10);
		multi *= 10;
		right /= 10;
	}

	printf(ret ? "TAK\n" : "NIE\n");
	return 0;
}