#include <iostream> #include <cmath> #include <sstream> bool isPrime(uint64_t number); int main() { std::string number; std::cin >> number; uint64_t length = number.length(); char const *digits = number.c_str(); if (length == 1) { std::cout << "NIE"; return 0; } if ((int) number[length - 1] != 2 + 48 && (int) number[length - 1] % 2 == 0) { std::cout << "NIE"; return 0; } for (int i = 0; i < length - 1; i++) { uint64_t firstPrime; uint64_t secondPrime; std::string fs = ""; std::string ss = ""; for (int j = 0; j <= i; j++) { fs += digits[j]; } for (int j = i + 1; j < length; j++) { ss += digits[j]; } if (ss[0] == '0') { continue; } std::istringstream issf(fs); std::istringstream isss(ss); issf >> firstPrime; isss >> secondPrime; if (isPrime(firstPrime) && isPrime(secondPrime)) { std::cout << "TAK"; return 0; } } std::cout << "NIE"; return 0; } bool isPrime(uint64_t number) { if (number <= 1) return false; else if (number <= 3) return true; for (uint64_t i = 2; i < sqrt(number) + 1; i++) { if (number % i == 0) { return false; } } return true; };
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 | #include <iostream> #include <cmath> #include <sstream> bool isPrime(uint64_t number); int main() { std::string number; std::cin >> number; uint64_t length = number.length(); char const *digits = number.c_str(); if (length == 1) { std::cout << "NIE"; return 0; } if ((int) number[length - 1] != 2 + 48 && (int) number[length - 1] % 2 == 0) { std::cout << "NIE"; return 0; } for (int i = 0; i < length - 1; i++) { uint64_t firstPrime; uint64_t secondPrime; std::string fs = ""; std::string ss = ""; for (int j = 0; j <= i; j++) { fs += digits[j]; } for (int j = i + 1; j < length; j++) { ss += digits[j]; } if (ss[0] == '0') { continue; } std::istringstream issf(fs); std::istringstream isss(ss); issf >> firstPrime; isss >> secondPrime; if (isPrime(firstPrime) && isPrime(secondPrime)) { std::cout << "TAK"; return 0; } } std::cout << "NIE"; return 0; } bool isPrime(uint64_t number) { if (number <= 1) return false; else if (number <= 3) return true; for (uint64_t i = 2; i < sqrt(number) + 1; i++) { if (number % i == 0) { return false; } } return true; }; |