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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	bool sito[1000000];
	int primes[80000];

	for (int i = 0; i<1000000; i++)
		sito[i] = true;

	int k = 0;
	sito[0] = false;
	sito[1] = false;
	sito[2] = true;
	for (int i = 2; i<1000000; i++)
	{
		if (sito[i])
		{
			primes[k] = i;
			k++;
			int j = 2 * i;
			while (j < 1000000)
			{
				sito[j] = false;
				j += i;
			}
		}
	}

	k--;

	string s;
	cin >> s;
	bool result = false;

	for (int i = 1; i<s.length(); i++)
	{
		//podział liczby z wejścia
		long long int a = 0;
		long long int b = 0;
		if (s[i] == '0')
			continue;
		for (int j = 0; j<i; j++)
			a += pow(10, i - j - 1)*(s[j] - '0');
		for (int j = i; j<s.length(); j++)
			b += pow(10, s.length() - j - 1)*(s[j] - '0');

		bool isAPrime = true;
		if (a == 1) isAPrime = false;
		int j = 0;
		while (primes[j] < sqrt(a) + 1 && a > 3)
		{
			if (a % primes[j] == 0)
			{
				isAPrime = false;
				break;
			}
			j++;
		}
		
		if (!isAPrime) continue;

		bool isBPrime = true;
		if (b == 1) isBPrime = false;
		j = 0;
		while (primes[j] < sqrt(b) + 1 && b > 3)
		{
			if (b % primes[j] == 0)
			{
				isBPrime = false;
				break;
			}
			j++;
		}

		if (isAPrime && isBPrime)
		{
			result = true;
			break;
		}
	}

	if (result == true)
		cout << "TAK" << endl;
	else
		cout << "NIE" << endl;

}