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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <fstream>
#include <random>

using namespace std;

typedef unsigned long long ull;

void multiply(ull& a, ull b, ull mod)
{
	ull res = 0;
	ull pow = 1;
	while (pow < b)
	{
		pow *= 2;
	}

	while (pow > 0)
	{
		res += res;
		res %= mod;

		if (pow & b)
		{
			res += a;
			res %= mod;
		}

		pow /= 2;
	}
	a = res;
}


bool millerRabin(ull a, ull p)
{
	ull res = 1;
	ull previous = 1;
	ull pow = 1;
	ull mod = p;
	p--;
	
	while (pow <= p)
		pow *= 2;

	pow /= 2; 

	while (pow > 0)
	{
		if (pow & p)
		{
			previous = res;
			multiply(res, res, mod);
			multiply(res, a, mod);
		}
		else
		{
			previous = res;
			multiply(res, res, mod);
			if (res == 1)
			{
				if (previous != 1 && previous != p)
					return false;
			}
		}
		pow /= 2;
	}
	if (res != 1)
		return false;
	return true;
}

int primes[] = { 2,3,5,7,11,13,17,19,23 };
bool isPrime(ull a)
{
	if (a == 0 || a == 1)
		return false;
	if (a % 2 == 0)
	{
		if (a == 2)
			return true;
		return false;
	}

	for (auto& val : primes)
	{
		if (val >= a)
			return true;

		if (!millerRabin(val, a))
			return false;
		
	}
	return true;
}

/*
int main()
{
	std::random_device r;
	std::default_random_engine e1(r());
	std::uniform_int_distribution<long long> dis(10, 10000000000000);
	ofstream out("wynik2.txt");
	for (int i = 10; i < 1000000; ++i)
	{
		ull n = dis(e1);
		//cin >> n;
		out << n << ' ';
		//cout << n << ' ';
		if (i % 100000 == 0)
			cout << i << '\n';
		ull right = 0;
		ull left = n;

		ull pow = 1;
		while (left > 0)
		{
			bool canCheck = true;
			if (left % 10 == 0)
				canCheck = false;

			right += pow * (left % 10);
			left /= 10;

			if (canCheck && isPrime(right) && isPrime(left))
			{
				out << "TAK\n";
				//return 0;
				break;
			}

			pow *= 10;
		}
		if (left == 0)
		{
			out << "NIE\n";
		}
	}
	
	return 0;
}*/

int main()
{
	ull n;
	cin >> n;

	ull right = 0;
	ull left = n;

	ull pow = 1;
	while (left > 0)
	{
		bool canCheck = true;
		if (left % 10 == 0)
			canCheck = false;

		right += pow * (left % 10);
		left /= 10;

		if (canCheck && isPrime(right) && isPrime(left))
		{
			cout << "TAK\n";
			return 0;
		}

		pow *= 10;
	}
	cout << "NIE\n";
	return 0;
}