Python求循环素数的题目,求大神帮忙看下我的代码错在哪里?
n=input()p=[True]*(n+1)p[0]=p[1]=Falseforiinrange(2,int(n**0.5+2)):ifnotp[i]:continue...
n = input()
p = [True] * (n + 1)
p[0] = p[1] = False
for i in range(2, int(n**0.5 + 2)):
if not p[i]:
continue
for j in range(i*i, n + 1, i):
p[j] = False
primes = [i for i in range(n + 1) if p[i]]
t=[]
count = 0
for _p in primes:
str_p = str(_p)
for i in range(len(str(_p))):
n_p = int(str_p[i:]+str_p[:i])
t.append(n_p)
for i in t:
if i not in primes:t=[]
if t!=[]:count+=1
print count
Online Judge一直显示“程序异常,exit code非0” 展开
p = [True] * (n + 1)
p[0] = p[1] = False
for i in range(2, int(n**0.5 + 2)):
if not p[i]:
continue
for j in range(i*i, n + 1, i):
p[j] = False
primes = [i for i in range(n + 1) if p[i]]
t=[]
count = 0
for _p in primes:
str_p = str(_p)
for i in range(len(str(_p))):
n_p = int(str_p[i:]+str_p[:i])
t.append(n_p)
for i in t:
if i not in primes:t=[]
if t!=[]:count+=1
print count
Online Judge一直显示“程序异常,exit code非0” 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |