#include <iostream> typedef unsigned long long LL; bool is_prime(LL x) { if (x == 1) return false; for (LL i = 3; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int main() { LL n; //ab LL a; LL b; bool skip = false; scanf("%llu", &n); a = n / 10; b = n % 10; LL last_digit = a % 10; if (b % 2 == 0 || b == 5) { if (is_prime(a)) { printf("TAK"); return 0; } printf("NIE"); return 0; } if (is_prime(a) && is_prime(b)) { printf("TAK"); return 0; } if (last_digit == 0) skip = true; LL exp = 10; while (a != 0) { if (skip) { if (last_digit != 0) skip = false; a /= 10; b += last_digit * exp; last_digit = a % 10; exp *= 10; continue; } if (is_prime(a) && is_prime(b)) { printf("TAK"); return 0; } if (last_digit == 0) skip = true; a /= 10; b += last_digit * exp; last_digit = a % 10; exp *= 10; } printf("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 | #include <iostream> typedef unsigned long long LL; bool is_prime(LL x) { if (x == 1) return false; for (LL i = 3; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int main() { LL n; //ab LL a; LL b; bool skip = false; scanf("%llu", &n); a = n / 10; b = n % 10; LL last_digit = a % 10; if (b % 2 == 0 || b == 5) { if (is_prime(a)) { printf("TAK"); return 0; } printf("NIE"); return 0; } if (is_prime(a) && is_prime(b)) { printf("TAK"); return 0; } if (last_digit == 0) skip = true; LL exp = 10; while (a != 0) { if (skip) { if (last_digit != 0) skip = false; a /= 10; b += last_digit * exp; last_digit = a % 10; exp *= 10; continue; } if (is_prime(a) && is_prime(b)) { printf("TAK"); return 0; } if (last_digit == 0) skip = true; a /= 10; b += last_digit * exp; last_digit = a % 10; exp *= 10; } printf("NIE"); return 0; } |