求出大于或等于 N 的最小回文素数。

回顾一下,如果一个数大于 1,且其因数只有 1 和它自身,那么这个数是素数。

例如,2,3,5,7,11 以及 13 是素数。

回顾一下,如果一个数从左往右读与从右往左读是一样的,那么这个数是回文数。

例如,12321 是回文数。

链接:https://leetcode.cn/problems/prime-palindrome

import math


def isPalindrome(n):
    return str(n) == str(n)[::-1]


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

class Solution(object):
    def primePalindrome(self, n):
        """
        :type n: int
        :rtype: int
        """
        N = n
        while True:
            couldBe = True
            if len(str(N)) % 2 == 0 and N > 11:
                s = ""
                for i in str(N):
                    s += "0"
                s = "1" + s
                N = int(s) + 1
            tmp = 0
            if N > 3:
                tmp = N % 6
            if N > 3 and tmp != 5 and tmp != 1:
                couldBe == False
            if couldBe:
                if isPalindrome(N):
                    if isPrime(N):
                        return N
            if tmp == 1:
                N += 4
            elif tmp == 5:
                N += 2
            else:
                N += 1