#include <iostream> using namespace std; string n; long long a, b, cnt, x; bool is_prime(long long a) { if(a == 0 || a == 1) return false; if(a == 2) return true; if(a % 2 == 0) return false; for(long long i = 3; i * i <= a; i += 2) if(a % i == 0) return false; return true; } int main() { ios_base :: sync_with_stdio(); cin >> n; if(n[0] == '0') { cout << "NIE" << endl; return 0; } for(int i = 0; i < n.length() - 1; ++i) { if(n[i + 1] == '0') continue; cnt = 1; a = 0; for(int j = i; j >= 0; --j) { x = (long long)((int)(n[j] - 48)); a += (cnt * x); cnt *= 10; } cnt = 1; b = 0; for(int j = n.length() - 1; j >= i + 1; --j) { x = (long long)((int)(n[j] - 48)); b += (cnt * x); cnt *= 10; } if(is_prime(a) && is_prime(b)) { cout << "TAK" << endl; return 0; } } cout << "NIE" << endl; 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 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> using namespace std; string n; long long a, b, cnt, x; bool is_prime(long long a) { if(a == 0 || a == 1) return false; if(a == 2) return true; if(a % 2 == 0) return false; for(long long i = 3; i * i <= a; i += 2) if(a % i == 0) return false; return true; } int main() { ios_base :: sync_with_stdio(); cin >> n; if(n[0] == '0') { cout << "NIE" << endl; return 0; } for(int i = 0; i < n.length() - 1; ++i) { if(n[i + 1] == '0') continue; cnt = 1; a = 0; for(int j = i; j >= 0; --j) { x = (long long)((int)(n[j] - 48)); a += (cnt * x); cnt *= 10; } cnt = 1; b = 0; for(int j = n.length() - 1; j >= i + 1; --j) { x = (long long)((int)(n[j] - 48)); b += (cnt * x); cnt *= 10; } if(is_prime(a) && is_prime(b)) { cout << "TAK" << endl; return 0; } } cout << "NIE" << endl; return 0; } |