//Maciej Staniszewski, XVIII liceum ogolnoksztalcace im. Jana Zamoyskiego w Warszawie #include <iostream> #include <set> #include <map> #include <vector> #include <queue> #include <stack> #include <algorithm> #include <string> #include <cmath> #include <ctime> #include <cstdlib> //#define DEB #ifdef DEB #define D(...) __VA_ARGS__ #else #define D(...) #endif #define ZAK 1000*1000+10 #define LOGZ 20 #define BASE (1<<LOGZ) #define MOD (1000*1000*1000+7) #define POD 997 #define REP(i, q) for(int i = 0; i<(int)q; ++i) #define IV inline void #define LL long long #define ULL unsigned long long #define UI unsigned int using namespace std; //endof boring string n; long long pot[16]; inline void fillPot() { pot[0] = 1; for (int i = 1; i < 16; i++) { pot[i] = pot[i - 1] * 10; } } inline long long stoi(int pocz, int kon) { long long res = 0; int ctr = 0; for (int i = kon; i >= pocz; i--) { res += (n[i] - '0') * pot[ctr]; ctr++; } return res; } inline bool isPrime(long long a) { bool res = 1; for (int i = 2; i * i <= a; i++) { if (a%i == 0) { res = 0; break; } } return res; } int main() { #ifndef DEB ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; fillPot(); bool czyDruga = 0; for (int i = 0; i < n.size()-1; i++) { if (n[i + 1] == '0') continue; long long lew = stoi(0, i); long long praw = stoi(i + 1, n.size() - 1); bool czyLew = isPrime(lew); bool czyPraw = isPrime(praw); if (czyLew && czyPraw) { czyDruga = 1; break; } } if (czyDruga) { cout << "TAK\n"; } else cout << "NIE\n"; //system("PAUSE"); 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 | //Maciej Staniszewski, XVIII liceum ogolnoksztalcace im. Jana Zamoyskiego w Warszawie #include <iostream> #include <set> #include <map> #include <vector> #include <queue> #include <stack> #include <algorithm> #include <string> #include <cmath> #include <ctime> #include <cstdlib> //#define DEB #ifdef DEB #define D(...) __VA_ARGS__ #else #define D(...) #endif #define ZAK 1000*1000+10 #define LOGZ 20 #define BASE (1<<LOGZ) #define MOD (1000*1000*1000+7) #define POD 997 #define REP(i, q) for(int i = 0; i<(int)q; ++i) #define IV inline void #define LL long long #define ULL unsigned long long #define UI unsigned int using namespace std; //endof boring string n; long long pot[16]; inline void fillPot() { pot[0] = 1; for (int i = 1; i < 16; i++) { pot[i] = pot[i - 1] * 10; } } inline long long stoi(int pocz, int kon) { long long res = 0; int ctr = 0; for (int i = kon; i >= pocz; i--) { res += (n[i] - '0') * pot[ctr]; ctr++; } return res; } inline bool isPrime(long long a) { bool res = 1; for (int i = 2; i * i <= a; i++) { if (a%i == 0) { res = 0; break; } } return res; } int main() { #ifndef DEB ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; fillPot(); bool czyDruga = 0; for (int i = 0; i < n.size()-1; i++) { if (n[i + 1] == '0') continue; long long lew = stoi(0, i); long long praw = stoi(i + 1, n.size() - 1); bool czyLew = isPrime(lew); bool czyPraw = isPrime(praw); if (czyLew && czyPraw) { czyDruga = 1; break; } } if (czyDruga) { cout << "TAK\n"; } else cout << "NIE\n"; //system("PAUSE"); return 0; } |