Ejemplo n.º 1
0
def euler_37():
    primes = lib.prime_gen()

    candidates = itertools.chain(*[itertools.product(['1', '2', '3', '5', '7', '9'], repeat=n) for n in range(2, 11)])

    truncatable_primes = (int(''.join(n)) for n in candidates if is_truncatable_prime((''.join(n))))
    return sum(list(itertools.islice(truncatable_primes, 11)))
Ejemplo n.º 2
0
def num_factors_via_prime(n):
    primes = lib.prime_gen()
    current_prime = next(primes)

    x = n
    pfacts = defaultdict(int)
    while not is_prime(n):
        while (n % current_prime) == 0:
            n = n // current_prime
            pfacts[current_prime] += 1
        current_prime = next(primes)

    if n != 1:
        pfacts[n] += 1

    return reduce(operator.mul, (x + 1 for x in pfacts.values()), 1)
Ejemplo n.º 3
0
def euler_35(m):
    primes = itertools.takewhile(lambda x: x < m, (n for n in lib.prime_gen()))
    circular_primes = filter(circular_filter, primes)
    return len(list(circular_primes))
Ejemplo n.º 4
0
    consecutive = 0
    while True:
        n = next(i)
        if len(prime_factors(n).keys()) >= 4:
            consecutive += 1
            if consecutive == 1:
                possible_retval = n

            if consecutive == 4:
                return possible_retval
        else:
            consecutive = 0


pregenned_primes = []
primes = lib.prime_gen()


def prime_factors(n):
    retval = defaultdict(int)

    for p in pregenned_primes:
        while n % p == 0:
            n /= p
            retval[p] += 1
            if n == 1:
                return retval

    while n > 1:
        p = next(primes)
        pregenned_primes.append(p)