Skip to content

Instantly share code, notes, and snippets.

@zrbecker
Created January 15, 2013 05:10
Show Gist options
  • Select an option

  • Save zrbecker/4536291 to your computer and use it in GitHub Desktop.

Select an option

Save zrbecker/4536291 to your computer and use it in GitHub Desktop.
def rwh_primes(n):
sieve = [True] * n
for i in xrange(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)/(2*i)+1)
return [2] + [i for i in xrange(3,n,2) if sieve[i]]
n = 10 ** 7
q = 11
primes = rwh_primes(n)
residues = [[] for _ in xrange(q)]
for p in primes:
residues[p % q].append(p)
for p in xrange(11):
print '%d = %d' % (p, len(residues[p]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment