#include <iostream> #include <sstream> #include <string> #include <algorithm> #define lld long long int #define SIEVE 3300000 #define MAXN 10000000000000ll using namespace std; char sieve[SIEVE]; // 1 - complex, 0 - prime void genSieve(char *t) { t[1] = 1; // as a rule even though it's not really not prime int p = 1; while (p * p < SIEVE) { while (t[p]) p++; for (int i = p * p; i < SIEVE; i += p) { t[i] = 1; } p++; } } int main() { string s; cin >> s; genSieve(sieve); char good = 0; for (int i = 1; i < s.size(); i++) { if (s[i] == '0') { continue; } lld pred = stoll(s.substr(0, i)); lld sufd = stoll(s.substr(i)); bool localgood = 1; if (pred == 1) localgood = 0; if (sufd == 1) localgood = 0; for (lld j = 1; j * j <= pred; j++) if (!sieve[j]) { if (pred % j == 0) localgood = 0; } for (lld j = 1; j * j <= sufd; j++) if (!sieve[j]) { if (sufd % j == 0) localgood = 0; } if (localgood) good = 1; } if (good) { cout << "TAK\n"; } else { cout << "NIE\n"; } 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 | #include <iostream> #include <sstream> #include <string> #include <algorithm> #define lld long long int #define SIEVE 3300000 #define MAXN 10000000000000ll using namespace std; char sieve[SIEVE]; // 1 - complex, 0 - prime void genSieve(char *t) { t[1] = 1; // as a rule even though it's not really not prime int p = 1; while (p * p < SIEVE) { while (t[p]) p++; for (int i = p * p; i < SIEVE; i += p) { t[i] = 1; } p++; } } int main() { string s; cin >> s; genSieve(sieve); char good = 0; for (int i = 1; i < s.size(); i++) { if (s[i] == '0') { continue; } lld pred = stoll(s.substr(0, i)); lld sufd = stoll(s.substr(i)); bool localgood = 1; if (pred == 1) localgood = 0; if (sufd == 1) localgood = 0; for (lld j = 1; j * j <= pred; j++) if (!sieve[j]) { if (pred % j == 0) localgood = 0; } for (lld j = 1; j * j <= sufd; j++) if (!sieve[j]) { if (sufd % j == 0) localgood = 0; } if (localgood) good = 1; } if (good) { cout << "TAK\n"; } else { cout << "NIE\n"; } return 0; } |