#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <utility>
using namespace std;
bool CzyPierwsza(int a)
{
int d = 11;
int temp = 0;
int templ = 0;
if(a == 2 || a == 3 || a == 5 || a == 7)
{
return true;
}
else
if(a%2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
{
return false;
}
else
{
while(d<=a)
{
temp = a/d;
if(temp == templ)
{
return true;
}
if(d*temp == a)
{
return false;
}
templ = temp;
d++;
}
return true;
}
}
pair<int, int> DwieLiczby(vector<int> a, int p)
{
string lewa = "";
string prawa = "";
for(int i=0; i<p; i++)
{
lewa += to_string(a[i]);
}
for(int j=p; j<a.size(); j++)
{
prawa += to_string(a[j]);
}
if(prawa[0] == '0')
{
pair <int, int> paraZ = make_pair(0,0);
return paraZ;
}
else
{
int le = atoi(lewa.c_str());
int pr = atoi(prawa.c_str());
pair <int, int> para = make_pair(le,pr);
return para;
}
}
bool CzyDruga(string a)
{
vector<int> spl;
int p = 1;
int l = 0;
int r = 0;
for(int i=0; i<a.size(); i++)
{
spl.push_back(a[i] - '0');
}
pair<int, int> para;
bool TempL = false;
bool TempR = false;
while(p <= spl.size()-1)
{
para = DwieLiczby(spl,p);
if((para.first && para.second) == 0)
{
p++;
}
else
{
TempL = CzyPierwsza(para.first);
TempR = CzyPierwsza(para.second);
if(TempL && TempR)
{
return true;
}
}
p++;
}
return false;
}
int main()
{
string x;
cin>>x;
if(CzyDruga(x))
{
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | #include <iostream> #include <cstdlib> #include <string> #include <vector> #include <utility> using namespace std; bool CzyPierwsza(int a) { int d = 11; int temp = 0; int templ = 0; if(a == 2 || a == 3 || a == 5 || a == 7) { return true; } else if(a%2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0) { return false; } else { while(d<=a) { temp = a/d; if(temp == templ) { return true; } if(d*temp == a) { return false; } templ = temp; d++; } return true; } } pair<int, int> DwieLiczby(vector<int> a, int p) { string lewa = ""; string prawa = ""; for(int i=0; i<p; i++) { lewa += to_string(a[i]); } for(int j=p; j<a.size(); j++) { prawa += to_string(a[j]); } if(prawa[0] == '0') { pair <int, int> paraZ = make_pair(0,0); return paraZ; } else { int le = atoi(lewa.c_str()); int pr = atoi(prawa.c_str()); pair <int, int> para = make_pair(le,pr); return para; } } bool CzyDruga(string a) { vector<int> spl; int p = 1; int l = 0; int r = 0; for(int i=0; i<a.size(); i++) { spl.push_back(a[i] - '0'); } pair<int, int> para; bool TempL = false; bool TempR = false; while(p <= spl.size()-1) { para = DwieLiczby(spl,p); if((para.first && para.second) == 0) { p++; } else { TempL = CzyPierwsza(para.first); TempR = CzyPierwsza(para.second); if(TempL && TempR) { return true; } } p++; } return false; } int main() { string x; cin>>x; if(CzyDruga(x)) { cout<<"TAK"<<endl; } else { cout<<"NIE"<<endl; } return 0; } |
English