# 
# Solution to Project Euler problem 58
# Philippe Legault
# 
# https://github.com/Bathlamos/Project-Euler-Solutions


from fractions import Fraction
from math import ceil, sqrt

def compute():
	num_primes = 3
	increment = 4
	t = 9
	while Fraction(num_primes, (increment - 2) * 2 + 1) >= Fraction(1, 10):
		for n in range(1, 5):
			if is_prime(t + increment * n):
				num_primes += 1
		t += increment * 4
		increment += 2

	return increment - 1

def is_prime(n):
	limit = int(ceil(sqrt(n))) + 1
	for i in range(2, limit):
		if n % i == 0:
			return False
	return True

if __name__ == "__main__":
	print(compute())