#include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> using namespace std; typedef long long ll; bool isPrime(ll n) { if (n == 2) return true; if (n % 2 == 0) return false; for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } vector<ll> digits(ll n) { vector<ll> d; while (n > 0) { d.push_back(n % 10); n /= 10; } return d; } ll fromInterval(const vector<ll>& d, int from, int to) { ll num = 0; for (int i = from; i <= to; ++i) num = num * 10 + d[i]; return num; } bool doit(ll n) { vector<ll> d = digits(n); reverse(d.begin(), d.end()); for (int i = 1; i < d.size(); ++i) { if (d[i] == 0) continue; ll a = fromInterval(d, 0, i - 1); ll b = fromInterval(d, i, d.size() - 1); if (isPrime(a) && isPrime(b)) return true; } return false; } int main() { char s[16]; scanf("%s", s); printf("%s\n", (s[0] != '0' && doit(atol(s))) ? "TAK" : "NIE"); }
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 67 68 69 70 71 72 73 74 75 76 | #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> using namespace std; typedef long long ll; bool isPrime(ll n) { if (n == 2) return true; if (n % 2 == 0) return false; for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } vector<ll> digits(ll n) { vector<ll> d; while (n > 0) { d.push_back(n % 10); n /= 10; } return d; } ll fromInterval(const vector<ll>& d, int from, int to) { ll num = 0; for (int i = from; i <= to; ++i) num = num * 10 + d[i]; return num; } bool doit(ll n) { vector<ll> d = digits(n); reverse(d.begin(), d.end()); for (int i = 1; i < d.size(); ++i) { if (d[i] == 0) continue; ll a = fromInterval(d, 0, i - 1); ll b = fromInterval(d, i, d.size() - 1); if (isPrime(a) && isPrime(b)) return true; } return false; } int main() { char s[16]; scanf("%s", s); printf("%s\n", (s[0] != '0' && doit(atol(s))) ? "TAK" : "NIE"); } |