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
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;

bool lpie (long long x)
{
	long long y=0;
	for(int i=1; i<=x; i++)
	{
		if(x%i==0) y++;
	}
	if (y==2) return 1;
	return 0;
}

int cyfry(long long liczba)
{
int b=1;
while(liczba=liczba/10)b++;
return b;
}

int main()
{
ios_base::sync_with_stdio(0);
long long n, m, f;
deque<int> dek;
int r, d, dzielnik, temp;
cin>>n;
m=n;
r=cyfry(n);
d=cyfry(n);
d--;

for (int i=0; i<r; i++)
{
	dzielnik=pow (10, d);
	f=m/dzielnik;
	dek.push_back(f); 
	m=m-dek[i]*dzielnik;
	d--;
} 
if (dek[r-1]==4||dek[r-1]==6||dek[r-1]==8||dek[r-1]==0)
{
	cout<<"NIE";
	return 0;
}

int pot, x, y=0, i=1;
if (r==2)
{
	x=dek[0];
	y=dek[1];
	if (lpie(x)==1 && lpie(y)==1) 
	{
		cout<<"TAK"<<endl;
		return 0;
	}
	else
	{
		cout<<"NIE"<<endl;
		return 0;
	}
}
x=dek[0];
pot=dek.size()-2;
while (pot>=0)
{
	y=y+dek[i]*pow(10, pot);
	i++;
	pot--;
}
pot=dek.size()-2;
if (y>=pow(10, pot) && lpie(x)==1 && lpie(y)==1) 
{
	cout<<"TAK"<<endl;
	return 0;
}
d=r-1;

int z=1, q=2;
while (d>1)
{
x=x*10;
x=x+dek[z];
pot=dek.size()-q;
y=y-dek[z]*pow(10, pot);
z++;
d--;
q++;
if (lpie(x)==1 && lpie(y)==1) 
{
	cout<<"TAK"<<endl;
	return 0;
}

}
cout<<"NIE";
return 0;
}