#include <iostream> #include <math.h> #include <vector> using namespace std; long long n; bool z[3200000]; vector <int> primes; void sito(int s) { for(int i=2; i*i<s; i++) { if(!z[i]) { for(int j=i*i; j<=s; j+=i) z[j] = true; } } } bool isPrime( long long u ) { if(u==0 || u == 1) return false; int i=0; while( primes[i]*primes[i] <= u ) { if( u%primes[i] == 0 ) return false; i++; } return true; } bool solve( long long q ) { long long p = 0; long long ten=1; while( q > 0 ) { p += ten*q%10; ten *= 10; if( q%10 == 0 ) { q /= 10; continue; } q /= 10; if( isPrime(p) && isPrime(q) ) return true; } return false; } int main() { cin>>n; sito( sqrt(n) ); for(int i=2; i<=sqrt(n); i++) { if(!z[i]) primes.push_back(i); } cout<<((solve(n))?("TAK"):("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 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 | #include <iostream> #include <math.h> #include <vector> using namespace std; long long n; bool z[3200000]; vector <int> primes; void sito(int s) { for(int i=2; i*i<s; i++) { if(!z[i]) { for(int j=i*i; j<=s; j+=i) z[j] = true; } } } bool isPrime( long long u ) { if(u==0 || u == 1) return false; int i=0; while( primes[i]*primes[i] <= u ) { if( u%primes[i] == 0 ) return false; i++; } return true; } bool solve( long long q ) { long long p = 0; long long ten=1; while( q > 0 ) { p += ten*q%10; ten *= 10; if( q%10 == 0 ) { q /= 10; continue; } q /= 10; if( isPrime(p) && isPrime(q) ) return true; } return false; } int main() { cin>>n; sito( sqrt(n) ); for(int i=2; i<=sqrt(n); i++) { if(!z[i]) primes.push_back(i); } cout<<((solve(n))?("TAK"):("NIE")); return 0; } |