import time
def Primedivisor(n): # This is a function that will try to find a (small) factor of a (large) prime n
for d in range(2, min(n,100000)): # We try to find a factor n, but give up if we get to 100000 with no luck
if n % d == 0: # If d divides n, success!
return d
d = d + 1 # Otherwise, keep trying (but give up at 100000)
return n # If no luck, return n, which may or may not be prime
listlength = int(input("How many 'small' primes do we look for? "))
Euclidprimes = [2] # Initialize the list at the single prime 2
while len(Euclidprimes) < listlength: # We'll stop when our list gets to the inputted length
Prod = 1
for i in range(len(Euclidprimes)): # Compute the Euclid number (product of the primes plus 1)
Prod = Prod*Euclidprimes[i]
Euclid = Prod + 1
print("This is the new Euclid number ", Euclid)
New = Primedivisor(Prod + 1) # Ship the Euclid number off to the function to try to find a small factor
print("This is the small factor of the Euclid number ", New)
for j in range(len(Euclidprimes)): # If the factor of the Euclid number really is small,
if Euclidprimes[j] > New: # redo the list of primes, shedding the big ones and only
Euclidprimes = Euclidprimes[0:j] + [New] # keeping the primes up to the new small one
break
elif j == len(Euclidprimes) - 1: # otherwise just tack the big number to the list and hope for the best
Euclidprimes = Euclidprimes + [New]
print(Euclidprimes) # print out the list we've got so far
print("")
time.sleep(5)