import sys
sys.setrecursionlimit (30000)
def isPrime(n, i = 2):
# Base cases
if (n <= 2):
return True if(n == 2) else False
if (n % i == 0):
return False
if (i * i > n):
return True
# Check for next divisor
return isPrime(n, i + 1)
def ispalindrome(word):
return word == word[::-1]
def primechecker(N, M):
if N == M:
if isPrime(N):
if ispalindrome(str(N)):
print(N)
if N < M:
if isPrime(N):
if ispalindrome(str(N)):
print(N)
return primechecker(N+1,M)
else:
return
N = int(input("Enter the starting point N:\n"))
M = int(input("Enter the ending point M:\n"))
print("The palindromic primes are:")
primechecker(N, M)