"""Solves Problem 10 for Project Euler."""importmathdefis_prime(candidate,known_primes):"""Determines whether candidate is prime by trial division using \ known_primes. For this function to work, known_primes *must* be accurate. """last_possible=math.sqrt(candidate)forcurrent_primeinknown_primes:ifcurrent_prime>last_possible:breakifnotcandidate%current_prime:returnFalsereturnTruedefprimes_generator(upper_bound):"""A generator for all the primes < upper_bound."""candidates=xrange(2,upper_bound)primes=[]fornincandidates:ifis_prime(n,primes):primes.append(n)yieldndefproblem_10():"""Sum the primes less than 2 million."""returnsum(primes_generator(2000000))if__name__=='__main__':printproblem_10()