# project euler 37

from primes import isprimelist

prime = isprimelist(10**6)

print sum([p for p in range(11, 10**6, 2) if prime[p] and all([prime[int(str(p)[q:])] and prime[int(str(p)[:-q])] for q in range(1, len(str(p)))])])
# project euler 27

from primes import isprimelist

results = dict()
primelist = isprimelist(50000)

for a in range(-999, 1000):
	for b in range(-999, 1000):
		n = 0
		while True:
			result = n*n + a*n + b 
			if result > 0 and primelist[result]:
				n += 1
			else:
				break
		results[n] = (a, b)
	
print max(results.items())