#include <iostream> #include <cmath> #define ll long long using namespace std; bool prime(ll x) { if(x < 2) { return false; } if(x < 4) { return true; } if((x%2)==0) { return false; } ll s = round(floor(sqrt(x))); for(ll i=3;i<=s;i+=2) { if((x%i)==0) { return false; } } return true; } int main(int argc, char** argv) { string n; cin>>n; int s = n.length(); bool res = false; for(int i=1;i<s;i++) { string a = n.substr(0,i); string b = n.substr(i); if((a.length() > 0) && (b.length() > 0) && (b[0] != '0') && prime(stoll(a)) && prime(stoll(b))) { res = true; break; } } cout<<(res?"TAK":"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 | #include <iostream> #include <cmath> #define ll long long using namespace std; bool prime(ll x) { if(x < 2) { return false; } if(x < 4) { return true; } if((x%2)==0) { return false; } ll s = round(floor(sqrt(x))); for(ll i=3;i<=s;i+=2) { if((x%i)==0) { return false; } } return true; } int main(int argc, char** argv) { string n; cin>>n; int s = n.length(); bool res = false; for(int i=1;i<s;i++) { string a = n.substr(0,i); string b = n.substr(i); if((a.length() > 0) && (b.length() > 0) && (b[0] != '0') && prime(stoll(a)) && prime(stoll(b))) { res = true; break; } } cout<<(res?"TAK":"NIE")<<endl; return 0; } |