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
#include <stdio.h>
#include <cstdint>

const int ERATO_SIZE = 500000 + 10;
unsigned char ERATO[ERATO_SIZE];

bool is_prime(uint64_t num) {
  if (num == 1) return false;
  if (num == 2) return true;
  if ((num % 2) == 0) return false;
  uint64_t i = 1;
  uint64_t j = 2*i + 1;
  while (j * j < num) {
  	if ((num % j) == 0) return false;
  	i++;
  	j = 2*i+1;
  }
  return true;
}

bool is_duoprime(uint64_t num) {
  uint64_t pos = 10;
  while (pos < num) {
  	uint64_t a = num / pos;
  	uint64_t b = num % pos;

    if (pos / 10 <= b) {
      if (is_prime(a) && is_prime(b)) {
      	return true;
      }
    }
  	pos *= 10;
  }
  return false;
}

int main() {
  // Create Eratosthenes sieve.
  for (int i = 0; i < ERATO_SIZE; ++i) ERATO[i] = 1;
  for (int i = 1; i * i < ERATO_SIZE; ++i) {
  	int jump = i * 2 + 1;
  	if (ERATO[i] == 1) {
  	  for (int j = i + jump; j < ERATO_SIZE; j += jump) ERATO[j] = 0;
  	}
  }

  uint64_t input;
  scanf("%lld", &input);

  printf("%s\n", is_duoprime(input) ? "TAK" : "NIE");

  return 0;
}