BC127 筛选法求素数

思路:

step1:

代码如下:注意end=‘ ’后再打印,需要自己加\n;

n = int(input())
i = 2
c = []
while i <= n:
    for j in range(i+1,n+1):
        if j%i == 0:
            c.append(j)
    i += 1
d = set(c)
e = len(d)
f = []
for i in range(2,n+1):
    if i not in d:
        f.append(i)
for i in f:
    print(i,end=' ')
print('\n'+'{}'.format(e))