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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

typedef long long int LL;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;
typedef std::vector<PII> VPII;

static const int INF = 1000000001;
static const double EPS = 10e-9;

#ifdef _MSC_VER
    #define VAR(v, n) auto v = (n)
#else
    #define VAR(v, n) __typeof__(n) v = (n)
#endif

#define REP(i, n) for (int _n = (n), i = 0; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FOREACH(it, c) for (VAR(it, (c).begin()); it != (c).end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define PB push_back
#define PF push front
#define ST first
#define ND second
#define MP std::make_pair

#define N 13
#define P 999983
#define PN 78498

LL get_number(const char* s, int b, int e)
{
    LL r = 0;

    FOR(i, b, e - 1)
    {
        r *= 10;
        r += s[i];
        r -= '0';
    }

    return r;
}

int sieve(int n, int p[])
{
    bool complex[P + 1] = { 0x00 };

    for (int i = 2; i * i <= n; ++i)
    {
        if (!complex[i])
        {
            for (int j = i * i; j <= n; j += i)
            {
                complex[j] = true;
            }
        }
    }

    int k = 0;
    for (int i = 2; i <= n; ++i)
    {
        if (!complex[i])
        {
            p[k++] = i;
        }
    }

    return k;
}

bool is_prime(LL n, int p[], int k)
{
    if ((n & 1) == 0)
    {
        return (n == 2);
    }

    if ((n % 3) == 0)
    {
        return (n == 3);
    }

    if ((n % 5) == 0)
    {
        return (n == 5);
    }

    if ((n % 7) == 0)
    {
        return (n == 7);
    }

    for (int i = 4; (i < k) && p[i] * p[i] <= n; ++i)
    {
        if ((n % p[i]) == 0)
        {
            return false;
        }
    }

    return true;
}

int main(void)
{
    char s[N + 1];
    int p[PN];
    int ignored = 0;

    ignored = scanf("%s", s);

    if (s[0] == '0')
    {
        ignored = printf("TAK\n");
        return 0;
    }

    int k = sieve(P, p);

    int n = strlen(s);

    FOR(i, 1, n - 1)
    {
        if (s[i] != '0')
        {
            LL l = get_number(s, 0, i);
            LL r = get_number(s, i, n);

            if (is_prime(l, p, k) && is_prime(r, p, k))
            {
                ignored = printf("TAK\n");
                return 0;
            }
        }
    }

    ignored = printf("NIE\n");

    (void) ignored;

    return 0;
}