#include <iostream> #include <cmath> using namespace std; using MyInt = unsigned long long int; bool isPrime(MyInt number) { // number >= 2 if (number == 2) return true; if (number % 2 == 0) return false; MyInt bound = sqrt(number) + 1; for (MyInt i = 3; i < bound; i += 2) if (number % i == 0) return false; return true; } int main() { // n >= 10 && n <= 10^13 MyInt n; cin >> n; constexpr double inv_power_ten = 0.1; MyInt power_ten = 10; MyInt lower; MyInt upper; do { lower = n % power_ten; if (lower * 10 >= power_ten) { upper = (n - lower) * inv_power_ten; if (upper && isPrime(upper) && isPrime(lower)) { cout << "TAK"; return 0; } } power_ten *= 10; } while (upper); cout << "NIE"; return 0; }
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 | #include <iostream> #include <cmath> using namespace std; using MyInt = unsigned long long int; bool isPrime(MyInt number) { // number >= 2 if (number == 2) return true; if (number % 2 == 0) return false; MyInt bound = sqrt(number) + 1; for (MyInt i = 3; i < bound; i += 2) if (number % i == 0) return false; return true; } int main() { // n >= 10 && n <= 10^13 MyInt n; cin >> n; constexpr double inv_power_ten = 0.1; MyInt power_ten = 10; MyInt lower; MyInt upper; do { lower = n % power_ten; if (lower * 10 >= power_ten) { upper = (n - lower) * inv_power_ten; if (upper && isPrime(upper) && isPrime(lower)) { cout << "TAK"; return 0; } } power_ten *= 10; } while (upper); cout << "NIE"; return 0; } |