Smallest Prime Palindrome
IntuitionThe goal is to find the smallest number  that is both prime and a palindrome.Approach

Check special case: If  is between 8 and 11, return 11.


Start
# Intuition
The goal is to find the smallest number  that is both prime and a palindrome.


# Approach

1. Check special case: If  is between 8 and 11, return 11.


2. Start from  and keep checking:

If  is a palindrome and prime, return it.

Otherwise, increase  and check again.
3. Optimizations:

Skip even numbers (except 2) since they can't be prime.

Skip even-length palindromes, as they are often divisible by 11.


# Complexity
- Time complexity : O(Sqrt(N))

- Space complexity : O(1)
# Code
```cpp []
class Solution {
public:
    bool is_palindrome(int n) {
        int num = n, reversed = 0;
        while (num) {
            reversed = reversed * 10 + num % 10;
            num /= 10;
        }
        return reversed == n;
    }

    bool is_prime(int n) {
        if (n <= 1)
            return false;
        if (n == 2 || n == 3)
            return true;
        if (n % 2 == 0)
            return false;
        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0)
                return false;
        }
        return true;
    }
    int Count_digit(int n) {
        int count = 0;
        while (n) {
            count++;
            n /= 10;
        }
        return count;
    }

    int primePalindrome(int n) {

        if (n >= 8 && n <= 11) {
            return 11;
        }
        while (true) {
            if (is_palindrome(n) && is_prime(n))
                return n;
            n++;

            if (n > 2 && n %  2 == 0)
                n++;

            if (Count_digit(n) % 2 == 0) {
                n = pow(10, Count_digit(n));
            }
        }
    }
};

```
['Math', 'Number Theory', 'C++']