示例#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))