Hi all, I wrote code to list primes that are in a given "radius" of an even number. For example, 6 - 1 = 5 and 6 + 1 = 7, 14 - 3 = 11 and 14 + 3 = 17, etc. I used Euler's sieve to obtain the primes. Can the following code be further optimized? If so, how? I eventually want to be able to plot the primes for a given even number. All help is appreciated, thanks!
Here's the code:
n = int(raw_input("Num: "))
s = range(3, n+1, 2)
i = 1
a = len(s) - 1
for l in xrange(0, a + 1):
a1 = i
j = (l + (s[l]*i))
while (j <= a) and s[l] != 0:
s[j] = 0
i += 1
j = (l + (s[l]*i))
i = a1 + 1
s = list(set(s))
s.sort()
s.remove(0)
# All the code above this point is an implementation of Euler's sieve.
a = s[-1] - 1
pR = []
pRc = []
for i in xrange(4, a + 1, 2):
for l in xrange(1, i - 2, 2):
c = i + l
d = i - l
if c in s and d in s:
pR.append(c)
pR.append(d)
for k in pR:
pRc.append(k)
pRc.append(str(i))
pR = []
print pRc