66分,3个TLE,dalao求调

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

zou_hero @ 2024-09-09 10:54:28

from math import sqrt,ceil
a,b = map(int,input().split())
list2=[]
for i in range(a, b+1):
    if (i % 2 != 0):
        if (str(i) == str(i)[::-1]):
            list2.append(i)
list1=[]
for i in list2:
    a=True
    if(i==2):
        print(i)
    else:
        for j in range(2,ceil(sqrt(i))+1):
            if(i%j==0):
                a=False
                break
        if a:
            print(i)

by fush @ 2024-09-09 11:38:03

除11以外的所有位数是偶数的,都不是回文质数


|