Exemplo n.º 1
0
def problem49():
    result = []
    primes = [x for x in prime_generator(10000)]
    d = 3330
    for n in xrange(1000, 10000):
        if n not in primes:
            continue
        n_str = str(n)
        per = [int(permutation(n_str, x)) for x in xrange(factorial(4))]
        pri = [x for x in per if x in primes]
        if n+d in pri and n+2*d in pri:
            result.append(str(n) + str(n+d) + str(n+d+d))
    return list(set(result))
Exemplo n.º 2
0
def problem37():

    max = 1000000
    primes = set([x for x in prime_generator(max)])
    result = []
    
    def is_truncable_prime(n):
        n = str(n)
        l = len(n)
        for i in xrange(l):
            if int(n[l-i-1:]) not in primes or int(n[:i+1]) not in primes:
                return False
        return True

    for x in xrange(10, max):
        print x
        if is_truncable_prime(x):
            result.append(x)
    print result, len(result)
    return sum(result)
Exemplo n.º 3
0
def problem46():
    max = 10**4
    primes = [x for x in prime_generator(max)]
    number = 3

    while number < max:
        number = number + 2 
        if number in primes:
            continue
        valid = 0
        for x in primes:
            if x >= number:
                break
            test = number - x
            square = sqrt(test/2)
            if test%2 == 0 and floor(square) == square:
                valid = 1
                break

        if valid == 0:
            return number

    return 0
Exemplo n.º 4
0
from eulerhelper import prime_generator

limit = 10000

prime_table = [x for x in prime_generator(limit)]

def countprimes(a, b):
    count = 0
    for n in xrange(limit):
        x = n*n + a*n + b
        if x > limit:
            print "Warning: limit exceeded. a=", a, "b=", b, "n=", n, "x=", x
        if x in prime_table:
            count = count + 1
        else:
            break
    return count

assert countprimes(1,41) == 40
assert countprimes(-79, 1601) == 80

def problem27():
    start = -1000
    end = 1000
    max = 0
    result = (0,0)

    for a in xrange(start, end+1):
        for b in xrange(start, end+1):
            count = countprimes(a, b)
            print a, b, count
Exemplo n.º 5
0
from eulerhelper import factorial, permutation, prime_generator

primes = [x for x in prime_generator(17)]

def divisiontest(number):
    for x in xrange(7):
        if int(number[x+1:x+4]) % primes[x] != 0:
            return False
    return True

assert divisiontest("1406357289")

def problem42():
    result = []
    pandigit = "0123456789"
    for x in xrange(factorial(10)-1):
        number = permutation(pandigit,x)
        if divisiontest(number):
            result.append(int(number))
    return sum(result)

print problem42()