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
102
103
104
105
106
107
108
109
110
111
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

namespace {

template<typename T>
constexpr T square(T x)
{
  return x*x;
}

template <typename T>
constexpr T ipow(T base, int power)
{
  return power == 0 ? 1 : (square(ipow(base, power / 2)) * (power % 2 == 0 ? 1 : base));
}

template <typename T>
constexpr T isqrt_next(T n, T x)
{
  return (x + n / x) / 2;
}

template <typename T>
constexpr T isqrt_helper(T n, T x1, T x2)
{
  return (x2 == x1 || x2 == x1 + 1) ? x1 : isqrt_helper(n, x2, isqrt_next(n, x2));
}

template <typename T>
constexpr T isqrt(T n)
{
  return isqrt_helper(n, n, isqrt_next(n, n));
}

constexpr auto max_n = ipow(10LL, 13);
constexpr auto max_p = isqrt(max_n);

template <int N>
struct Sieve {
  bool is_prime[N];
  vector<int> primes;

  Sieve()
  {
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < N; ++i) {
      is_prime[i] = true;
    }

    for (int p = 2; p <= N / p; ++p) {
      if (!is_prime[p]) continue;
      for (int q = p * p; q < N; q += p) {
        is_prime[q] = false;
      }
    }
    for (int i = 2; i < N; ++i) {
      if (is_prime[i]) primes.emplace_back(i);
    }
  }
};

bool is_prime(long long n)
{
  static Sieve<max_p> sieve;
  if (n < max_p) return sieve.is_prime[n];
  for (int p: sieve.primes) {
    if (p > n / p) break;
    if (n % p == 0) return false;
  }
  return true;
}

bool is_prime(long long a, long long b)
{
  if (a > b) swap(a, b);
  return is_prime(a) && is_prime(b);
}

bool solve(long long n)
{
  long long l = n;
  long long r = 0;
  long long p = 1;
  while (l > 0) {
    int d = l % 10;
    l /= 10;
    r += d * p;
    p *= 10;
    if (d != 0 && is_prime(l, r)) {
      return true;
    }
  }
  return false;
}

}

int main()
{
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);

  long long n;
  cin >> n;
  cout << (solve(n) ? "TAK" : "NIE") << endl;

  return 0;
}