#include <iostream> //#include <cstdio> #include <cmath> #define DEB(f_, ...) //printf((f_), __VA_ARGS__) typedef long long ll; bool isPrime(ll k) { if(k == 1) { return false; } ll s = sqrt(k); for(int d = 2; d <= s; d++) { if(k % d == 0) { return false; } } return true; } bool isDrime(ll n) { for(ll tenp = 10; tenp <= n; tenp *= 10) { ll left = n / tenp; ll right = n % tenp; if(right >= tenp/10 && isPrime(right) && isPrime(left)) { DEB("%lld|%lld\n", left, right); return true; } } return false; } int main() { ll n; std::cin >> n; std::cout << (isDrime(n) ? "TAK" : "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 | #include <iostream> //#include <cstdio> #include <cmath> #define DEB(f_, ...) //printf((f_), __VA_ARGS__) typedef long long ll; bool isPrime(ll k) { if(k == 1) { return false; } ll s = sqrt(k); for(int d = 2; d <= s; d++) { if(k % d == 0) { return false; } } return true; } bool isDrime(ll n) { for(ll tenp = 10; tenp <= n; tenp *= 10) { ll left = n / tenp; ll right = n % tenp; if(right >= tenp/10 && isPrime(right) && isPrime(left)) { DEB("%lld|%lld\n", left, right); return true; } } return false; } int main() { ll n; std::cin >> n; std::cout << (isDrime(n) ? "TAK" : "NIE") << "\n"; return 0; } |