def factors_of_a_number(n): prime_candidates = primes_util.erastot_sieve(int(round(n**0.5))) current = int(n) factors = {} while(current > 1): if primes_util.is_prime(current): prime = current if not current in factors: factors[current] = 1 else: factors[current] = factors[current]+1 break for prime in prime_candidates: if current % prime == 0: #if the remainder of the division is 0, it's a divisor if not prime in factors: factors[prime] = 1 else: factors[prime] = factors[prime]+1 current = current/prime break return factors
''' The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. ''' import primes_util print reduce(lambda x,y: x+y, primes_util.erastot_sieve(2000000))