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
69
70
71
72
73
74
75
76
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <cmath>

#define LL long long

using namespace std;

vector<LL> primes;

void prepare_primes(LL n) {
	LL bound = (LL) sqrt(n);
	LL bound_sqrt = (LL) sqrt(bound);

	bool * crossed = new bool[bound + 1];
	memset(crossed, false, bound + 1);
	crossed[0] = crossed[1] = true;
	for (int i = 2; i <= bound_sqrt; i++) for (int j = i * 2; j <= bound; j += i) crossed[j] = true;
	for (int i = 2; i <= bound; i++) if (!crossed[i]) {
		primes.push_back(i);
	}

	delete [] crossed;
}

long long make_long(char * chars, int start, int end) {
	LL result = 0;
	for (int i = start; i < end; i++) {
		result = result * 10 + (chars[i] - '0');
	}
	return result;
}

vector< pair<LL, LL> > pairs(LL n) {
	char * n_chars = new char[15];
	sprintf(n_chars, "%lld", n);
	int n_chars_len = strlen(n_chars);
	
	vector<pair<LL, LL>> result;
	for (int i = 1; i < n_chars_len; i++) if (n_chars[i] != '0')
		result.push_back(make_pair(make_long(n_chars, 0, i), make_long(n_chars, i, n_chars_len)));

	delete [] n_chars;
	return result;
}

bool is_prime(LL n) {
	if (n < 2)
		return false;
	LL n_sqrt = (LL) sqrt(n);
	for (vector<LL>::iterator it = primes.begin(); it != primes.end(); it++) {
		if ((*it) * (*it) > n) return true;
		if (n % (*it) == 0) return false;
	}
	return true;
}

int main() {
	LL n;
	scanf("%lld", &n);

	prepare_primes(n);
	vector<pair<LL,LL>> ps = pairs(n);

	bool proof_found = false;
	for (vector<pair<LL,LL>> ::iterator it = ps.begin(); it != ps.end(); it++) {
		if (is_prime(it->first) && is_prime(it->second)) {
			proof_found = true;
		}
	}
	printf("%s\n", proof_found ? "TAK" : "NIE");
	
	return 0;
}