예제 #1
0
파일: mix.py 프로젝트: tomik/euler
def 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.
    """

    return sum(elib.primes_to(2000000))
예제 #2
0
파일: e005.py 프로젝트: tomik/euler
def smallest_divisible_by(dividers):
    max_divider = max(list(dividers))
    primes = elib.primes_to(max_divider)
    #min to start with
    min = reduce(lambda x, y: x* y, primes, 1)
    act = min
    while True:
        for d in dividers:
            if act % d != 0:
                act += min
                break
        else:
            return act
예제 #3
0
파일: mix.py 프로젝트: tomik/euler
def problem_35():
    """
    The number, 197, is called a circular prime because all rotations of the digits: 
        197, 971, and 719, are themselves prime.
    There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
    How many circular primes are there below one million?
    """

    primes = set(elib.primes_to(1000000))
    circulars = 0
    for prime in primes:
        is_circular = True
        for rotation in elib.digit_rotator(prime): 
            if rotation not in primes: 
                is_circular = False
                break

        if is_circular:
            circulars += 1

    return circulars
예제 #4
0
파일: e027.py 프로젝트: tomik/euler
def gen_coefs(min_limit, max_limit):
    return ((a, b) for a in xrange(min_limit, max_limit)
                   for b in elib.primes_to(max_limit))