コード例 #1
0
ファイル: p12.py プロジェクト: gsc/euler
def main():
    """
    The most expensive process (computationally) is the factor calculation.
    """

    found_solution = False
    i = 1
    primes = euler.eratosthenes_sieve(200000)

    max_factors = 0

    while not found_solution:
        i += 1
        num = triangle(i)

        prime_candidates = [x for x in primes if x <= num]
        prime_factors = get_prime_factors(num, prime_candidates)

        all_factors = get_all_factors(num, Set(prime_factors))

        if len(all_factors) > max_factors:
            max_factors = len(all_factors)
            print "max num factors: %d" % max_factors

        found_solution = len(all_factors) > 500

    print "The first triangle number with more than 500 factors is %d " % num
コード例 #2
0
ファイル: p10.py プロジェクト: gsc/euler
def main():
    """
    Compute the list of all primes below 2 millions using the erathostenes sieve
    and add it up.
    """
    primes = euler.eratosthenes_sieve(2000000)
    print "The sum of all primes below 2 million is %d " % sum(primes)