N = 1001 count = [0]*N l = list(range(2, N)) def countP(n): for i in range(2, n): count[i] = count[i-1] + 1 if i in l else count[i-1] for j in range(count[i]): if i * l[j] >= n: break l.remove(i*l[j]) if not i % l[j]: break countP(N) print(count[1000] - count[99]) #print(143)