Exemple #1
0
def factorizer(n) :
    return factorize2( prime_factors2( n, primes_cached() ) )
Exemple #2
0
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes
"""

from pe10 import primes_cached, prime_cache
from bisect import bisect_left

def index(lst, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect_left(lst, x)
    if i != len(lst) and lst[i] == x:
        return i
    return -1

is_prime = lambda p : index(prime_cache, p) != -1

def is_truncatable(p) :
    if p < 10 : return False
    digits = list(str(p))
    return all( is_prime(int(''.join(digits[:i])))
            and is_prime(int(''.join(digits[i:])))
            for i in xrange(1,len(digits)))

#zip to take exactly 11 elements (takewhile would never find the 12th)
tp = list( p for i,p in zip( xrange(11), ( p for p in primes_cached() if is_truncatable(p)) ))

s = sum(tp)

assert s == 748317