I'm implementing the Sieve of Eratosthenes in Python. It returns composite numbers near the end of the search range:
def primes_Ero(n=1000):
primes = []
a = [True]*(n+1)
a[0] = a[1] = False
for (i,isprime) in enumerate(a):
if isprime:
for n in range(i*i,n+1, i):
a[n] = False
primes.append(i)
return primes
When using larger numbers, n, I end up with composite numbers. I made a check to see which numbers are composite (compared to a brute force method),
Given n, what numbers are composite:
n= 100; []
n= 500; [493, 497]
n= 1000; [961, 989]
n= 10000; [9701, 9727, 9797, 9853, 9869, 9917, 9943, 9953, 9983, 9991, 9997]
What am I doing wrong?