#include <iostream> #include <cstdint> #include <utility> typedef std::pair<uint64_t, uint64_t> IntPair; bool isPrime(uint64_t n) { if (n == 2) { return true; } if (n < 2 || n % 2 == 0) { return false; } for (uint64_t i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } uint64_t pow(uint64_t base, uint32_t exp) { return exp == 0 ? 1 : base * pow(base, exp - 1); } // split number so that the second one has exactly pos digits IntPair split(uint64_t number, uint32_t pos) { uint64_t p = pow(10, pos); uint64_t first = number / p; uint64_t second = number % p; if (second < p / 10) second = 0; // split not available return std::make_pair(first, second); } int main() { uint64_t n, pos = 1; std::cin >> n; while (true) { IntPair s = split(n, pos); if (s.first == 0) { std::cout << "NIE" << std::endl; return 0; } if (isPrime(s.first) && isPrime(s.second)) { std::cout << "TAK" << std::endl; return 0; } ++pos; } }
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 | #include <iostream> #include <cstdint> #include <utility> typedef std::pair<uint64_t, uint64_t> IntPair; bool isPrime(uint64_t n) { if (n == 2) { return true; } if (n < 2 || n % 2 == 0) { return false; } for (uint64_t i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } uint64_t pow(uint64_t base, uint32_t exp) { return exp == 0 ? 1 : base * pow(base, exp - 1); } // split number so that the second one has exactly pos digits IntPair split(uint64_t number, uint32_t pos) { uint64_t p = pow(10, pos); uint64_t first = number / p; uint64_t second = number % p; if (second < p / 10) second = 0; // split not available return std::make_pair(first, second); } int main() { uint64_t n, pos = 1; std::cin >> n; while (true) { IntPair s = split(n, pos); if (s.first == 0) { std::cout << "NIE" << std::endl; return 0; } if (isPrime(s.first) && isPrime(s.second)) { std::cout << "TAK" << std::endl; return 0; } ++pos; } } |