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
#include <iostream>
#include <cstdlib>
typedef unsigned long long ll;

ll mnoz(ll a, ll b, ll mod)
{
	ll res = 0;
	while (b > 0)
	{
		if (b % 2 == 1)
		{
			res += a;
		}
		a += a;
		a %= mod;
		res %= mod;
		b /= 2;
	}
	return res % mod;
}

static ll pow_mod(ll a, ll x, ll n)
{
	ll r = 1;
	while (x)
	{
		if ((x & 1) == 1)
			r = mnoz(a, r, n);

		x >>= 1;
		a = mnoz(a, a, n);
	}

	return r;
}

bool isprime(ll n, int k = 50)
{
	if (n == 2 || n == 3) return true;
	if (n <= 1 || !(n & 1)) return false;

	int s = 0;
	for (ll m = n - 1; !(m & 1); ++s, m >>= 1);

	ll d = (n - 1) / (1 << s);

	for (int i = 0; i < k; ++i)
	{
		ll a = rand() % (n - 4) + 2;
		ll x = pow_mod(a, d, n);

		if (x == 1 || x == n - 1)
			continue;

		for (int r = 1; r <= s - 1; ++r)
		{
			x = pow_mod(x, 2, n);
			if (x == 1) return false;
			if (x == n - 1) goto LOOP;
		}

		return false;
	LOOP:
		continue;
	}

	return true;
}

using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, temp, licznik = 1;
	cin >> n;
	temp = n % 10;
	n /= 10;
	while (n > 0)
	{
		licznik *= 10;
		if (isprime(n) && isprime(temp))
		{
			cout << "TAK\n";
			return 0;
		}
		ll x = n % 10;
		while (x == 0)
		{
			licznik *= 10;
			n /= 10;
			x = n % 10;
		}
		temp += licznik * x;
		n /= 10;
	}
	cout << "NIE\n";
	return 0;
}