def main(): # question asks to check BELOW 2 million sum = 0 for i in range(1, total): if is_prime(i): sum += i print 'final sum of the primes is: {}'.format(sum)
def prime_factors_of( multiple ) : factors = [] maximum = multiple + 1 while multiple <> 1 : for number in xrange( 2, maximum ) : if is_factor( number, multiple ) and is_prime( number ) : factors.append( number ) multiple = multiple / number return factors
def prime_factors_of(multiple): factors = [] maximum = multiple + 1 while multiple <> 1: for number in xrange(2, maximum): if is_factor(number, multiple) and is_prime(number): factors.append(number) multiple = multiple / number return factors
#!/usr/bin/python # Project Euler (projecteuler.net) # # Problem 5: Smallest multiple # # 2520 is the smallest number that can be divided by each of the numbers from # 1 to 10 without any reminder # What is the smallest positive number that is evenly divisible by all of the # numbers from 1 to 20? # this is probably too ineficient # check if there is a better way from p3_largest_prime_factor import is_prime if __name__ == "__main__" : n = 2000000 sumation = 0 for test_number in xrange( 2, n + 1 ) : if is_prime( test_number ) : sumation += test_number print "The sum of all primes below", n, "is ", sumation
#!/usr/bin/python # Project Euler (projecteuler.net) # # Problem 5: Smallest multiple # # 2520 is the smallest number that can be divided by each of the numbers from # 1 to 10 without any reminder # What is the smallest positive number that is evenly divisible by all of the # numbers from 1 to 20? # this is probably too ineficient # check if there is a better way from p3_largest_prime_factor import is_prime if __name__ == "__main__": n = 2000000 sumation = 0 for test_number in xrange(2, n + 1): if is_prime(test_number): sumation += test_number print "The sum of all primes below", n, "is ", sumation
#!/usr/bin/python # Project Euler (projecteuler.net) # # Problem 7: 100001st prime # # By listing the first six prime numbers: 2, 3, 5, 7, 11 and 13, we can see # that the 6th prime is 13. # What is the 10,001st prime number? from p3_largest_prime_factor import is_prime if __name__ == "__main__" : n = 10001 prime_counter = 0 test_int = 1 while prime_counter < n : test_int += 1 if is_prime( test_int ) : prime_counter += 1 print "The", prime_counter, "th prime number is ", test_int
#!/usr/bin/python # Project Euler (projecteuler.net) # # Problem 7: 100001st prime # # By listing the first six prime numbers: 2, 3, 5, 7, 11 and 13, we can see # that the 6th prime is 13. # What is the 10,001st prime number? from p3_largest_prime_factor import is_prime if __name__ == "__main__": n = 10001 prime_counter = 0 test_int = 1 while prime_counter < n: test_int += 1 if is_prime(test_int): prime_counter += 1 print "The", prime_counter, "th prime number is ", test_int