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
#include <iostream>
#include <math.h>

using namespace std;

bool is_prime(long long n) {
    bool prime = true;
    if ( n < 2 )
        return false;
    long long s = sqrt(n);
    long long i = 2;
    while ( prime && i <= s ) {
        if ( n % i == 0 )
            prime = false;
        i++;
    }
    
    return prime;
}

int main(int argc, const char * argv[]) {
    long long n, n1, n2;
    cin >> n;
    bool secondary = false;
    if ( n % 10 == 0 )
        cout << "NIE";
    string s = to_string(n);
    string s1, s2;
    long l = s.length();
    long l1, l2;
    l1 = 1;
    while ( l1 < l && !secondary ) {
        l2 = l - l1;
        if ( s[l1] == '0' ) {
            l1++;
        } else {
            s1 = s.substr(0, l1);
            s2 = s.substr(l1, l2);
            n1 = stoll(s1);
            n2 = stoll(s2);
            if ( n1 < n2 )
                secondary = is_prime(n1) && is_prime(n2);
            else
                secondary = is_prime(n2) && is_prime(n1);
            l1++;
        }
    }
    
    if ( secondary )
        cout << "TAK";
    else
        cout << "NIE";
    
    return 0;
}