#include <iostream> #include <cstring> using namespace std; const int M=4000000; bool sito[M]; bool czyPierwsza(long long n) { for (int i=2; i<n; ++i) if (sito[i]) { if (n%i==0) return false; if (n<=i*(long long) i) break; } return true; } bool czyDruga(long long n) { long long d=1, m=0; while (9<n) { int x=n%10; n/=10; m+=d*x; if (x && czyPierwsza(n) && czyPierwsza(m)) return true; d*=10; } return false; } int main() { memset(sito, 1, sizeof(sito)); for (int i=2; i<M; ++i) if (sito[i]) for (int j=2*i; j<M; j+=i) sito[j]=false; long long n; cin>>n; cout<<(czyDruga(n) ? "TAK" : "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 | #include <iostream> #include <cstring> using namespace std; const int M=4000000; bool sito[M]; bool czyPierwsza(long long n) { for (int i=2; i<n; ++i) if (sito[i]) { if (n%i==0) return false; if (n<=i*(long long) i) break; } return true; } bool czyDruga(long long n) { long long d=1, m=0; while (9<n) { int x=n%10; n/=10; m+=d*x; if (x && czyPierwsza(n) && czyPierwsza(m)) return true; d*=10; } return false; } int main() { memset(sito, 1, sizeof(sito)); for (int i=2; i<M; ++i) if (sito[i]) for (int j=2*i; j<M; j+=i) sito[j]=false; long long n; cin>>n; cout<<(czyDruga(n) ? "TAK" : "NIE")<<endl; return 0; } |