import math

def is_prime(n):
	if n < 2:
		return False
	n_sqrt = int(math.sqrt(n))+1
	i = 2
	while i < n_sqrt:
		if n%i == 0:
				return False
		i += 1
	return True
	
max_primes = 0
max_product = 0
for a in range(-1000,1001):
	for b in range(-1000,1001):
		primes = 0
		for n in range (0,80):
			p = n**2 + a*n + b
			if is_prime(p):
				primes += 1
		if primes > max_primes:
			max_primes = primes
			max_product = a*b
			print 'New max! ',a,b,a*b,primes
		#elif primes > 0:
		#	break

print max_product

##http://projecteuler.net/problem=27
##f(n) = n^2 + an + b
##
##f(0) = b => b - prime
##f(1) = a+b+1 => a - odd

# from funkcje import isprime
# import time
# start = time.time()
# 
# b_candidates = set(k for k in range(2,1000) if isprime(k))
# a_candidates = set(k for k in range(-999,1000,2))
# 
# 
# def consecutive_primes_fn(a, b):
#     '''(int, int) -> int
# 
#     Return number of consecutive primes generated by f(n) with
#     parameteres a, b.
# 
#     >>> consecutive_primes_fn(1,41)
#     40
#     >>> consecutive_primes_fn(-79, 1601)
#     80
#     '''
#     result = 0
#     k = 0
#     helper = k**2 + a*k + b
#     while helper > 0 and isprime(helper):
#         result += 1
#         k += 1
#         helper = k**2 + a*k + b
#     return result
# 
# 
# def euler27():
#     max_n = 0
#     product = 0
#     for a in a_candidates:
#         for b in b_candidates:
#             temp = consecutive_primes_fn(a,b)
#             if temp > max_n:
#                 max_n = temp
#                 product = a*b
#     return product                
# 
#     
# if __name__ == '__main__':
#     import doctest
#     doctest.testmod()
# 
# 
# print euler27()
# end = time.time()
# print end-start

##result: -59231
##time elapsed: 4.31599998474