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
#include <iostream>

#include <string>

#include <cmath>

#include <math.h>

using namespace std;

bool oblicz(string a, int b)
{
	long long c, d, e=0, sqrC, sqrD;
	for (int i=a.length()-1; i>=0; i--)
	{
		//cout << a[i]-48;
		e += (a[i]-48) * pow(10, a.length()-1-i);
	//	cout << a[i]-48 << " " << pow(10, a.length()-1-i) << endl;
	}
	
	//cout << endl;
	//cout << e;
	c = e / pow(10, a.length()-b);
	d = pow(10, a.length()-b);
//	cout << b << ":"  << endl;
//	cout << d << endl;
	d = e % d;
	//cout << d << endl;
	sqrC = sqrt(c)+1;
	sqrD = sqrt(d)+1;
	for (int i=3; i<sqrC; i++)
	{
		if (c%i==0)
		{
			return false;
		}
	}
	for (int i=3; i<sqrD; i++)
	{
		if (d%i==0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	string a;
	cin >> a;
	if ( a[a.length()-1]-48 == 0 || a[a.length()-1]-48 == 4 || a[a.length()-1]-48 == 6 || a[a.length()-1]-48 == 8  )
	{
		cout << "NIE";
		return 0;
	}
	
	for (int i=1; i<a.length(); i++)
	{
		if (a[i-1]-48 != 0 && a[i-1]-48 != 4 && a[i-1]-48 != 6 && a[i-1]-48 != 8 && a[i]-48 != 0)
		{
			//cout << a[i]-48;
			if (i!=a.length()-1 && (a[a.length()-1]-48==2 || a[a.length()-1]-48==5))
			{}
			else
			{
			//	cout << "hej";
				if(oblicz(a, i)==true)
				{
					cout << "TAK";
					return 0;
				}
			}
		}
		
	}
	cout << "NIE";
}