题解 | #筛选法求素数#
筛选法求素数
http://www.nowcoder.com/practice/06c3dcc303654ef4926654023eca1e5a
import math
def isPrime(n):
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
while True:
try:
num=input()
num_list=list(range(2,int(num)+1))
for i in range(len(num_list)):
if isPrime(num_list[i]):
print(num_list[i],end=" ")
else:
num_list[i]=0
print("\n{}".format(num_list.count(0)))
except:
break