#include <cstdio> #include <cstdlib> using namespace std; int is_prime(long long int n) { if (n <= 1) return 0; if (n == 2) return 1; if (n % 2 == 0) return 0; for (long long int i = 3; i * i <= n; i += 2) { if (n % i == 0) return 0; } return 1; } int main() { long long int n, a = 0; scanf("%lld", &n); long long int i = 1; while (n > 0) { int d = n % 10; a += i * d; n /= 10; i *= 10; if (d > 0 && is_prime(a) && is_prime(n)) { printf("TAK\n"); return 0; } } printf("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 | #include <cstdio> #include <cstdlib> using namespace std; int is_prime(long long int n) { if (n <= 1) return 0; if (n == 2) return 1; if (n % 2 == 0) return 0; for (long long int i = 3; i * i <= n; i += 2) { if (n % i == 0) return 0; } return 1; } int main() { long long int n, a = 0; scanf("%lld", &n); long long int i = 1; while (n > 0) { int d = n % 10; a += i * d; n /= 10; i *= 10; if (d > 0 && is_prime(a) && is_prime(n)) { printf("TAK\n"); return 0; } } printf("NIE\n"); return 0; } |