#include<stdio.h> #include<iostream> using namespace std; bool startsWithZero(string s) { return s[0] == '0'; } bool isPrimary(unsigned long long n) { if(n<2) { return false; } for(unsigned long long i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } bool isPrimary(string s) { unsigned long long num; sscanf(s.c_str(), "%llu", &num); return isPrimary(num); } int main() { string numberAsString; getline(cin, numberAsString); size_t size = numberAsString.size(); bool found = false; if(!startsWithZero(numberAsString)) { for(int firstLength = 1; firstLength<size; ++firstLength) { string firstPart = numberAsString.substr(0, firstLength); string secondPart = numberAsString.substr(firstLength, size - firstLength); if(startsWithZero(secondPart)) { continue; } if(isPrimary(secondPart) && isPrimary(firstPart)){ found = true; break; } } } if(found){ cout << "TAK"; }else{ cout << "NIE"; } 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 | #include<stdio.h> #include<iostream> using namespace std; bool startsWithZero(string s) { return s[0] == '0'; } bool isPrimary(unsigned long long n) { if(n<2) { return false; } for(unsigned long long i=2;i*i<=n;i++) { if(n%i==0) return false; } return true; } bool isPrimary(string s) { unsigned long long num; sscanf(s.c_str(), "%llu", &num); return isPrimary(num); } int main() { string numberAsString; getline(cin, numberAsString); size_t size = numberAsString.size(); bool found = false; if(!startsWithZero(numberAsString)) { for(int firstLength = 1; firstLength<size; ++firstLength) { string firstPart = numberAsString.substr(0, firstLength); string secondPart = numberAsString.substr(firstLength, size - firstLength); if(startsWithZero(secondPart)) { continue; } if(isPrimary(secondPart) && isPrimary(firstPart)){ found = true; break; } } } if(found){ cout << "TAK"; }else{ cout << "NIE"; } return 0; } |