def nth_prime(nth): counter = 1 #includes 2, start at 3 i = 1 while counter < nth: i += 2 if isPrime(i): counter += 1 print i
def nth_prime(nth): counter = 1 # includes 2, start at 3 i = 1 while counter < nth: i += 2 if isPrime(i): counter += 1 print i
def factor_primes(n): prime_factors = {} for f in define_factors(n): if isPrime(f): e = 0 while n % f == 0: n = n / f e += 1 prime_factors[f] = e return prime_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 time from pe3_LPF import isPrime ceiling = 2000000 i = 3 sum = 2 t0 = time.time() while i < ceiling: if isPrime(i): sum += i i += 2 t1 = time.time() print sum print "time: ", t1 - t0