def f(x, i = 2,test = True):
while i <= x ** .5:
if not x % i:
test = False
break
i += 1
return test
n = int(input())
for k in range(1,n):
if f(k):
print(k, end=' ')
Вводим 100, получаем
n = int(input())
n1 = []
for i in range(2, n):
for j in range(2, i+1):
if j == 2 or j == 3 or j == 5 or j == 7:
n1.append(j)
if j % 2 != 0 and j % 3 != 0 and j % 5 != 0 and j % 7 != 0:
n1.append(j)
n1 = list(set(n1))
print(*n1)
На вводе 256 решение перестает работать.
Ответы:
test #1
input: 11
output: 2 3 5 7
test #2
input: 15
output: 2 3 5 7 11 13
test #3
input: 3
output: 2
test #4
input: 6
output: 2 3 5
test #5
input: 256
output: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251