#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool pierwsza(long long int x)
{
if(x<2)
return false;
for(int i=2; i<sqrt(x); i++)
if(x%i==0)
return false;
return true;
}
bool spr(string s)
{
bool t[2] = {false, false};
long long int l=0;
int index=0;
for(unsigned int i=0; i<s.size(); i++)
{
l*=10;
l+=s[i]-48;
if(pierwsza(l))
{
t[1]=t[0];
t[0]=true;
}
else{
t[1]=t[0];
t[0]=false;
if(t[1])
{
l=s[i]-48;
index++;
if(s[i]=='0')
{
return false;
}
}
}
}
if(pierwsza(l))
{
index++;
l=0;
}
if(l==0 and index>1)
return true;
else
return false;
}
int main()
{
string s;
cin >> s;
if(spr(s))
cout << "TAK" << endl;
else
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 56 57 58 59 60 61 62 63 64 65 | #include <iostream> #include <string> #include <cmath> using namespace std; bool pierwsza(long long int x) { if(x<2) return false; for(int i=2; i<sqrt(x); i++) if(x%i==0) return false; return true; } bool spr(string s) { bool t[2] = {false, false}; long long int l=0; int index=0; for(unsigned int i=0; i<s.size(); i++) { l*=10; l+=s[i]-48; if(pierwsza(l)) { t[1]=t[0]; t[0]=true; } else{ t[1]=t[0]; t[0]=false; if(t[1]) { l=s[i]-48; index++; if(s[i]=='0') { return false; } } } } if(pierwsza(l)) { index++; l=0; } if(l==0 and index>1) return true; else return false; } int main() { string s; cin >> s; if(spr(s)) cout << "TAK" << endl; else cout << "NIE" << endl; return 0; } |
English