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
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

const long long LIMIT = 3162279;
int mem[LIMIT];
vector<int> sp;

bool isPrime(int x) {
  for (int i : sp)
    if (i < x && (x%i == 0)) {
      return false;
    }
  return true;
}

int main() {

  memset(mem, 1, sizeof mem);
  mem[0] = mem[1] = 0;

  for (int i = 4; i < LIMIT-1; i += 2) 
    mem[i] = 0;

  for (int i = 3; i < LIMIT-1; i += 2) {
    if (mem[i]) {
      for (int k = i*2; k < LIMIT-1; k += i) {
        mem[k] = 0;
      }
    }
  }

  for (int i = 2; i < LIMIT-1; ++i)
    if (mem[i])
      sp.push_back(i);


  string n;
  cin >> n;

  for (int i = 1; i < n.size(); ++i) {
    string n1s = n.substr(0,i);
    string n2s = n.substr(i);
    long long n1 = atoll(n1s.c_str());
    long long n2 = atoll(n2s.c_str());

    if (n1 == 0 || to_string(n2) != n2s)
      continue;

    if (isPrime(n1) && isPrime(n2)) {
      cout << "TAK" << endl;
      return 0;
    }
  }
  cout << "NIE" << endl;

  return 0;
}