def prime_list(a):
b=[1]
for i in range(2,int(a**0.5)+1):
b+=[m*i for m in range(i,a//i+1)]
sa=set(range(1,a+1))
sb=set(b)
prime=sorted(list(sa-sb))
return prime
import time
t1=time.time()
mm=len(prime_list(10000000))
t2=time.time()
print(mm)
print('耗时:',t2-t1)
返回
664579
耗时: 18.870527267456055
网友评论