#include <iostream> #include <string> using namespace std; bool is_prime(long long a) { if (a == 1) return false; for (long long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } bool solve(string s) { for (int i = 1; i < s.size(); i++) { string a(s.begin(), s.begin() + i); string b(s.begin() + i, s.end()); if (a[0] == '0' || b[0] == '0') continue; auto c = stoll(a); auto d = stoll(b); bool prime = is_prime(c) && is_prime(d); if (prime) return true; } return false; } int main () { string s; cin >> s; cout << (solve(s) ? "TAK" : "NIE") << endl; }
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 | #include <iostream> #include <string> using namespace std; bool is_prime(long long a) { if (a == 1) return false; for (long long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } bool solve(string s) { for (int i = 1; i < s.size(); i++) { string a(s.begin(), s.begin() + i); string b(s.begin() + i, s.end()); if (a[0] == '0' || b[0] == '0') continue; auto c = stoll(a); auto d = stoll(b); bool prime = is_prime(c) && is_prime(d); if (prime) return true; } return false; } int main () { string s; cin >> s; cout << (solve(s) ? "TAK" : "NIE") << endl; } |