Skip to content

Instantly share code, notes, and snippets.

@cswiercz
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cswiercz/16db3d47098c7910422b to your computer and use it in GitHub Desktop.
Save cswiercz/16db3d47098c7910422b to your computer and use it in GitHub Desktop.
Computing "Small" Gaussian Primes
from sympy import isprime
from itertools import ifilter, count
def find_b(a):
"""Returns smallest b such that a^2 + b^2 is prime."""
f = lambda b: isprime(a**2 + b**2)
g = ifilter(f, count())
b = g.next()
return b
# for each a = 1,...,N compute the smallest b
# such that a+bi is a Gaussian prime
N = 10000
a = range(1, N)
b = map(find_b, a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment