def is_prime(number):
if number > 1:
if number == 2:
return True
if number % 2 == 0:
return False
for current in range(3, int(math.sqrt(number) + 1), 2):
if number % current == 0:
return False
return True
return False
def next_prime(n):
while True:
if is_prime(n):
yield n
n +=1
import math
print is_prime(15)
"""
A primal quadratic equation has coefficients a, b such that
where for a range of n,,
n**2 + a*n + b == p
and p is prime.
since it must be true for n==0, it follows that b must be prime.
So we can start by looking at the positive primes between 0 and 1000 for b.
for each of those, consider all values -1000 to 1000 for a, and see how high n gets before we
reach a non-prime.
since it must work for n==1, we also know that a+b is prime. since b is prime,
"""
def count_primes(a,b):
# return number of consecutive primes for n**2 + a*n + b
primal = True
n = 0
while primal:
p = n**2 + a*n + b
if not is_prime(p):
primal = False
return n
n += 1
print count_primes(1,41)
print count_primes(-79,1601)
possible_bs = [i for i in range(0,1001) if is_prime(i)]
print possible_bs[:10]
def search_quads():
maxsofar = [0,0,0]
for b in possible_bs:
for a in range(1001):
checkpos = [a,b,count_primes(a, b)]
checkneg = [-a,b,count_primes(-a, b)]
maxsofar = max(maxsofar,checkpos, checkneg,key = lambda x: x[-1])
return maxsofar
print search_quads()
print -61*971