py求助,超时比较严重,有人能提供一下优化方法吗
查看原帖
py求助,超时比较严重,有人能提供一下优化方法吗
605483
F_Suzichen楼主2022/12/23 15:42
import math

a,b=input().split()
a=int(a)
b=int(b)
c=[]
d=[]
def spi(h):
    for i in range(2,int(math.sqrt(h)+1)):
        if h%i==0:
            return 0
    else:
        return 1
for i in range(a,b+1):
    if spi(i):
        j=str(i)
        c.append(j)

for i in c:
    t=i[::-1]
    if t in i:
        d.append(i)

for i in d:
    print(i)

2022/12/23 15:42
加载中...