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
#include <algorithm>
#include <iostream>

bool
is_prime(unsigned long long num)
{
  if (num % 2 == 0) {
    return num == 2;
  }
  for (unsigned long long div = 3; div * div <= num; div += 2) {
    if (num % div == 0) {
      return false;
    }
  }
  return num > 1;
}

int
main(void)
{
  unsigned long long n;

  std::cin >> n;

  // Check all possible splits
  for (unsigned long long div = 10; div < n; div *= 10) {
    unsigned long long low = n % div;
    unsigned long long hi = n / div;

    // Protect against leading 0s
    if ((10 * low) / div > 0 && is_prime(hi) && is_prime(low)) {
      std::cout << "TAK" << std::endl;
      return 0;
    }
  }
  std::cout << "NIE" << std::endl;

  return 0;
}