#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
bool czypierwsza(string s) {
long long a = atoll(s.c_str());
int n=s.size();
for (int i=2; i*i<n; i++)
if (a%i==0) return false;
return true;
}
int main() {
string n, a, b;
cin>>n;
//1 przypadek
if (n[0]=='2' or n[0]=='3' or n[0]=='5' or n[0]=='7') {
if (n[1]!='0') {
a = n.substr(1, n.size()-1);
if (czypierwsza(a)) {
cout<<"TAK";
return 0;
}
}
else if (n[1]=='0') {
cout<<"NIE";
return 0;
}
}
//2 przypadek
if (n[n.size()-1]=='2' or n[n.size()-1]=='3' or n[n.size()-1]=='5' or n[n.size()-1]=='7')
if (n[n.size()-2]!='0' and n[n.size()-2]!='2' and n[n.size()-2]!='4' and n[n.size()-2]!='6' and n[n.size()-2]!='8') {
a = n.substr(1, n.size()-1);
//cout<<a<<endl;
if (czypierwsza(a)) {
cout<<"TAK";
return 0;
}
}
//ostatni przypadek
if (n[n.size()-1]!='0' and n[n.size()-1]!='2' and n[n.size()-1]!='4' and n[n.size()-1]!='6' and n[n.size()-1]!='8')
for (int i=n.size()-3; i>=0; i--)
if (n[i]!='0' or n[i]!='2' or n[i]!='4' or n[i]!='6' or n[i]!='8') {
a = n.substr(0, i);
if (czypierwsza(a)) {
b = n.substr(i+1, n.size()-1);
if (czypierwsza(b)) {
cout<<"TAK";
return 0;
}
}
}
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 | #include <iostream> #include <string> #include <cstdlib> using namespace std; bool czypierwsza(string s) { long long a = atoll(s.c_str()); int n=s.size(); for (int i=2; i*i<n; i++) if (a%i==0) return false; return true; } int main() { string n, a, b; cin>>n; //1 przypadek if (n[0]=='2' or n[0]=='3' or n[0]=='5' or n[0]=='7') { if (n[1]!='0') { a = n.substr(1, n.size()-1); if (czypierwsza(a)) { cout<<"TAK"; return 0; } } else if (n[1]=='0') { cout<<"NIE"; return 0; } } //2 przypadek if (n[n.size()-1]=='2' or n[n.size()-1]=='3' or n[n.size()-1]=='5' or n[n.size()-1]=='7') if (n[n.size()-2]!='0' and n[n.size()-2]!='2' and n[n.size()-2]!='4' and n[n.size()-2]!='6' and n[n.size()-2]!='8') { a = n.substr(1, n.size()-1); //cout<<a<<endl; if (czypierwsza(a)) { cout<<"TAK"; return 0; } } //ostatni przypadek if (n[n.size()-1]!='0' and n[n.size()-1]!='2' and n[n.size()-1]!='4' and n[n.size()-1]!='6' and n[n.size()-1]!='8') for (int i=n.size()-3; i>=0; i--) if (n[i]!='0' or n[i]!='2' or n[i]!='4' or n[i]!='6' or n[i]!='8') { a = n.substr(0, i); if (czypierwsza(a)) { b = n.substr(i+1, n.size()-1); if (czypierwsza(b)) { cout<<"TAK"; return 0; } } } cout<<"NIE"; return 0; } |
English