Python 3求助,最后3个TLE!
查看原帖
Python 3求助,最后3个TLE!
1066716
zsl_ayt楼主2023/11/11 16:59
def is_prime(x):
    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1
    return True


def huiwen(x):
    s = str(x)
    if s == s[::-1]:
        return True
    return False


def check(x):
    if x > 10 and x < 100 and x != 11 or x > 1000 and x < 10000:
        return False
    if x > 100000 and x < 1000000 or x > 10000000 and x < 100000000:
        return False
    return True


n, m = map(int, input().split())

for x in range(n, m + 1):
    if x > 10000000:
        break
    if check(x) and huiwen(x) and is_prime(x):
        print(x)
2023/11/11 16:59
加载中...