#include<iostream> #include<cmath> using namespace std; int ten_powers[15]; bool is_prime(unsigned long long a){ if(a == 0 || a == 1) return false; unsigned long long maxi = sqrt(a); for(unsigned long long i = 2; i <= maxi; i++){ if(a%i == 0) return false; } return true; } bool is_secondary(unsigned long long a){ for(int i = 1; i<15; ++i){ if(is_prime(a/ten_powers[i]) && is_prime(a%ten_powers[i]) && a%ten_powers[i] >= ten_powers[i-1]){ return true;} } return false; } int main(){ ten_powers[0] = 1; for(int i = 1; i<15; ++i) ten_powers[i] = 10*ten_powers[i-1]; unsigned long long a; cin >> a; if(is_secondary(a)) cout << "TAK"; else 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 | #include<iostream> #include<cmath> using namespace std; int ten_powers[15]; bool is_prime(unsigned long long a){ if(a == 0 || a == 1) return false; unsigned long long maxi = sqrt(a); for(unsigned long long i = 2; i <= maxi; i++){ if(a%i == 0) return false; } return true; } bool is_secondary(unsigned long long a){ for(int i = 1; i<15; ++i){ if(is_prime(a/ten_powers[i]) && is_prime(a%ten_powers[i]) && a%ten_powers[i] >= ten_powers[i-1]){ return true;} } return false; } int main(){ ten_powers[0] = 1; for(int i = 1; i<15; ++i) ten_powers[i] = 10*ten_powers[i-1]; unsigned long long a; cin >> a; if(is_secondary(a)) cout << "TAK"; else cout << "NIE"; return 0; } |