Example #1
0
# 1 to 10 without any remainder.
#
# What is the smallest positive number that is evenly divisible by all of the
# numbers from 1 to 20?
#
# Joaquin Derrac - [email protected]
#
################################################################################

from common.primes import get_sieve, factorize

if __name__ == "__main__":

    end = 20

    sieve = get_sieve(end)

    primes = [x for x in xrange(2, end + 1) if sieve[x]]

    factors_group = {}

    for i in xrange(2, end + 1):
        factors = factorize(i, primes)

        for factor in factors:

            if factor not in factors_group or factors_group[factor] < factors[factor]:
                factors_group[factor] = factors[factor]

    solution = 1
Example #2
0
#!/usr/bin/env python

################################################################################
#
# Project Euler - Problem 10
#
# The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
#
# Find the sum of all the primes below two million.
#
# Joaquin Derrac - [email protected]
#
################################################################################

from common.primes import get_sieve

if __name__ == "__main__":

    limit = 2000000
    solution = 0

    sieve = get_sieve(limit)

    for i in xrange(0, limit):
        if sieve[i]:
            solution += i

    print solution