Exemple #1
0
def nines(d):
    primes = []
    for exp in range(10):

        powers = [x for x in range(10)]
        powers.remove(exp)
        base_digits = sum([d * 10**i for i in powers])
        for i in range(10):
            if exp == 9 and i == 0: continue
            candidate = base_digits + i * 10**exp
            if isPrime(candidate):
                primes.append(candidate)
    return primes
Exemple #2
0
def eights(d):
    primes = []
    replacement_exponents = [x for x in combinations(range(10), 2)]
    for (a, b) in replacement_exponents:
        powers = [x for x in range(10)]
        powers.remove(a)
        powers.remove(b)

        base_digits = sum([d * 10**i for i in powers])

        for i in range(10):
            for j in range(10):
                if b == 9 and j == 0: continue
                candidate = base_digits + i * 10**a + j * 10**b
                if isPrime(candidate):
                    primes.append(candidate)
    return primes
Exemple #3
0

def sum_digits(n):
    r = 0
    while n:
        r, n = r + n % 10, n / 10
    return r


s = 0
#prime_lookup = defaultdict(bool)

xList = [1, 2, 4, 6, 8]
iterCount = 0
while iterCount < 12:
    newList = []
    for n in xList:
        for i in range(10):
            x = n * 10 + i
            if x % sum_digits(x) == 0: newList.append(x)
    for n in newList:
        for i in [1, 3, 7, 9]:
            x = n * 10 + i
            if int(str(n)[0]) != 1 and isPrime(
                    n / sum_digits(n)) and isPrime(x):
                s += x
                print x

    xList = newList[:]
    iterCount += 1
Exemple #4
0
from numtheory import isPrime
import time

t = time.clock()

a, b, c = {}, {}, {}
a[0], b[0] = 2, 19
hits = [1, 2, 19]

n = 1

while len(hits) < 2000:

    a[n] = 6 * n + a[n - 1]

    if isPrime(6 * (n) + 5) and isPrime(6 * (n) + 7) and isPrime(12 *
                                                                 (n) + 17):
        hits.append(a[n])

    b[n] = 6 * (n + 2) + b[n - 1]

    if isPrime(6 * (n) + 11) and isPrime(6 * (n) + 17) and isPrime(12 *
                                                                   (n) + 17):
        hits.append(b[n])

    n += 1

print hits[-1]

print time.clock() - t, "seconds"
Exemple #5
0
    for (a, b) in replacement_exponents:
        powers = [x for x in range(10)]
        powers.remove(a)
        powers.remove(b)

        base_digits = sum([d * 10**i for i in powers])

        for i in range(10):
            for j in range(10):
                if b == 9 and j == 0: continue
                candidate = base_digits + i * 10**a + j * 10**b
                if isPrime(candidate):
                    primes.append(candidate)
    return primes


s = 0

for i in range(1, 10):
    for j in [1, 3, 7, 9]:
        candidate = i * 10**9 + j
        if isPrime(candidate):
            s += candidate

for d in range(1, 10):
    nine_list = nines(d)
    print nine_list
    s += sum(nine_list)
    if len(nine_list) == 0:
        s += sum(eights(d))
print s