Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
##
#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
Exemple #6
0
##
#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