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
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

typedef unsigned long long  uint64;

vector<uint64> primes;

void CountPrimes(uint64 n) {
  primes.resize(1, 2);
  uint64 nmax = n;// / 10, nn = n % 10;
//  if(nmax < nn)
//    nmax = nn;
  nmax = (double)sqrt((double)nmax);
  for(uint64 number = 3; number < nmax; number += 2) {
    for(size_t i = 0; i < primes.size(); ++i) {
      uint64 num = primes[i];
      if(num * num > number) {
        primes.push_back(number);
        break;
      }
      if(number % num == 0)
        break;
    }
  }
}

bool IsPrime(uint64 number) {
  uint64 n = (double)sqrt((double)number);
  for(size_t i = 0; primes[i] <= n; ++i) {
    if((number % primes[i]) == 0)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  //cin.tie(NULL);
  long long n;
  cin >> n;

  CountPrimes(n);

  for(long long partition = 10; partition < n; partition *= 10) {
    long long first = n / partition;
    long long second = n % partition;
    if(second * 10 / partition == 0)
      continue;
    if(!IsPrime(first))
      continue;
    if(!IsPrime(second))
      continue;
    cout << "TAK\n";
    return 0;
  }
  cout << "NIE\n";
  return 0;
}