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
#include <cstdio>

int cands[1000002];
int primes[78498];

int main() {
  // sieve
  int z = 0;
  for (int i = 2; i < 1000002; i++) {
    cands[i] = i;
  }
  for (int i = 2; i < 1000002; i++) {
    if(cands[i]) {
      primes[z++] = i;
      int j = i * 2;
      while (j < 1000002) {
        if(cands[j])
          cands[j] = 0;
        j += i;
      }
    }
  }

  long long int num;
  scanf("%lli", &num);
  long long int pairs[13][2];
  long long int divider = 10;
  // split number to maximum 13 pairs:
  for(int i = 0; i < 13; i++) {
    pairs[i][0] = num / divider;
    pairs[i][1] = num % divider;
    if (num % divider == num % (divider/10)) // leading zero
      pairs[i][1] = 0;
    divider *= 10;
  }
  for(int j = 0; j < z; j++) {
    for(int i = 0; i < 13; i++) { 
      if(pairs[i][0] && pairs[i][1]) {
        if(pairs[i][0] > primes[j] && pairs[i][0] % primes[j] == 0) {
          pairs[i][0] = 0;
          continue;
        }
        if(pairs[i][1] > primes[j] && pairs[i][1] % primes[j] == 0) {
          pairs[i][1] = 0;
          continue;
        }
      }
    }
  }
  // check solution
  bool any = false;
  for(int i = 0; i < 13; i++)
    if (pairs[i][0] && pairs[i][1])
      any = true;  
  printf(any?"TAK\n":"NIE\n");
  return 0;
}