#include <bits/stdc++.h> using namespace std; bool prime(int x){ if (x == 1 or x == 0) return false; for (int i = 2; i * i <= x; i ++) if (! (x % i)) return false; return true; } int ato(string x){ int l = 0; for (int i = 0; i < x.length(); i ++){ l *= 10; l += (x[i] - '0'); } return l; } int main(){ string n; cin >> n; for (int i = 0; i < n.length() - 1; i ++) if (n[i + 1] != '0'){ //cout << i << endl; string x1 = ""; string x2 = ""; for (int j = 0; j <= i; j ++) x1 += n[j]; for (int j = i + 1; j < n.length(); j ++) x2 += n[j]; //cout << ato(x1) << " " << ato(x2) << endl; if (prime(ato(x1)) and prime(ato(x2))){ 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 | #include <bits/stdc++.h> using namespace std; bool prime(int x){ if (x == 1 or x == 0) return false; for (int i = 2; i * i <= x; i ++) if (! (x % i)) return false; return true; } int ato(string x){ int l = 0; for (int i = 0; i < x.length(); i ++){ l *= 10; l += (x[i] - '0'); } return l; } int main(){ string n; cin >> n; for (int i = 0; i < n.length() - 1; i ++) if (n[i + 1] != '0'){ //cout << i << endl; string x1 = ""; string x2 = ""; for (int j = 0; j <= i; j ++) x1 += n[j]; for (int j = i + 1; j < n.length(); j ++) x2 += n[j]; //cout << ato(x1) << " " << ato(x2) << endl; if (prime(ato(x1)) and prime(ato(x2))){ cout << "TAK"; return 0; } } cout << "NIE"; return 0; } |