#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
for(int i = 2; i*i <= n; i++)
{
if(n % i == 0)
{
return false;
}
}
return true;
}
bool check(string &s)
{
if(s.size() < 2)
return false;
for(int i=1; i<s.size(); i++)
{
ll n = 0, k=0;
if(s[i] == '0')
{
continue;
}
for(int j=0; j<i; j++)
{
n *= 10;
n += s[j] - '0';
}
for(int j=i; j<s.size(); j++)
{
k *= 10;
k += s[j] - '0';
}
//cout << n << " " << k << "\n";
if(isPrime(n) && isPrime(k) )
return true;
}
return false;
}
int main()
{
//ios_base::sync_with_stdio(0);
string s;
getline(cin, s);
//cout << "here\n";
if(check(s))
{
cout << "TAK\n";
}
else
{
cout << "NIE\n";
}
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; bool isPrime(ll n) { for(int i = 2; i*i <= n; i++) { if(n % i == 0) { return false; } } return true; } bool check(string &s) { if(s.size() < 2) return false; for(int i=1; i<s.size(); i++) { ll n = 0, k=0; if(s[i] == '0') { continue; } for(int j=0; j<i; j++) { n *= 10; n += s[j] - '0'; } for(int j=i; j<s.size(); j++) { k *= 10; k += s[j] - '0'; } //cout << n << " " << k << "\n"; if(isPrime(n) && isPrime(k) ) return true; } return false; } int main() { //ios_base::sync_with_stdio(0); string s; getline(cin, s); //cout << "here\n"; if(check(s)) { cout << "TAK\n"; } else { cout << "NIE\n"; } return 0; } |
English