66 python 还有3个TLE 求助!!

P1217 [USACO1.5] 回文质数 Prime Palindromes

Xi3414954826 @ 2024-03-02 15:35:25

# 超时啦 TLE  66分
def is_prime(num):
    flag = True
    if num < 2:
        flag = False
    if num % 2 == 1:
        for i in range(2,int(num**0.5)+1):
            if num % i == 0:
                flag = False
                break
    else:
        flag = False
    if num == 2:
        flag = True
    return flag

def is_huiwen(num):
    num = str(num)
    if num == num[::-1]:
        return True
    else:
        return False

a,b = map(int,input().split())
for i in range(a,b+1):
    if is_huiwen(i):
        if is_prime(i):
            print(i)

|