<p>Given an integer n, return <em>the smallest <strong>prime palindrome</strong> greater than or equal to </em><code>n</code>.</p>

<p>An integer is <strong>prime</strong> if it has exactly two divisors: <code>1</code> and itself. Note that <code>1</code> is not a prime number.</p>

<ul>
	<li>For example, <code>2</code>, <code>3</code>, <code>5</code>, <code>7</code>, <code>11</code>, and <code>13</code> are all primes.</li>
</ul>

<p>An integer is a <strong>palindrome</strong> if it reads the same from left to right as it does from right to left.</p>

<ul>
	<li>For example, <code>101</code> and <code>12321</code> are palindromes.</li>
</ul>

<p>The test cases are generated so that the answer always exists and is in the range <code>[2, 2 * 10<sup>8</sup>]</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 6
<strong>Output:</strong> 7
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 8
<strong>Output:</strong> 11
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> n = 13
<strong>Output:</strong> 101
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>8</sup></code></li>
</ul>

"""
class Solution:
    @staticmethod
    def is_palindrome(x):
        return (s := str(x)) == s[::-1]
    
    @staticmethod
    def is_prime(x):
        if x < 2:
            return False
        for i in range(2, int(x**0.5 + 1)):
            if not x % i:
                return False
        return True

    def primePalindrome(self, n: int) -> int:
        while True:
            if Solution.is_palindrome(n) and Solution.is_prime(n):
                return n
            n += 1
            if 10**7 < n < 10**8: # There are no prime palindromes in this range
                n = 10**8
"""

class Solution:

    def isPrime(x):
        for j in range(3,int(math.sqrt(x))+1,2):
            if (x%j==0):
                return False
        return True

    def isPalindrome(y):
        num=y
        rev=0
        while num!=0:
            rem=num%10
            rev=rev*10+rem
            num=num//10
        if y==rev:
            return True
        return False

    def primePalindrome(self, n: int) -> int:
        if (n==1) or (n==2):
            return 2
        if n==3:
            return 3
        if (n==4) or (n==5):
            return 5
        if (n==6) or (n==7):
            return 7
        if (n==8) or (n==9) or (n==10) or (n==11):
            return 11
        if n%2==0:
            n+=1
        
        while True:

            if (n%2!=0) and (n%5!=0):
                if Solution.isPalindrome(n) and Solution.isPrime(n):
                    return n  
            n+=1   
            
            if 10**7 < n < 10**8:
                n = 10**8
                 


        
        
16700