Esempio n. 1
0
def solve():
    limit = 50000000
    primes_a = list(gen_primes(int(limit**0.5)))
    primes_b = list(gen_primes(int(limit**0.34)))
    primes_c = list(gen_primes(int(limit**0.25)))
    result = set()

    for a in primes_a:
        for b in primes_b:
            for c in primes_c:
                result.add(a**2 + b**3 + c**4)

    print len([x for x in result if x < limit])
Esempio n. 2
0
def solve():
    total = 0
    for prime in gen_primes():
        if prime > 2000000:
            break
        total += prime
    return total
Esempio n. 3
0
def solve():
    result = []
    primes = set()

    for x in gen_primes():
        primes.add(x)
        if x <= 7:
            continue
        if all(y in primes for y in truncate_left(x)) and all(y in primes for y in truncate_right(x)):
            result.append(x)
            if len(result) == 11:
                break

    return sum(result)
Esempio n. 4
0
def solve():
    x = 5

    while True:
        if not is_prime(x):
            for p in gen_primes(x):
                a = x - p
                if a % 2 == 0:
                    b = a / 2
                    b = sqrt(b)
                    if b.is_integer():
                        break
            else:
                return x
        x += 2
Esempio n. 5
0
def solve():
    primes = list(gen_primes(1000000))
    primes_ = set(primes)
    result = defaultdict(list)

    for i in xrange(len(primes)):
        s = 0
        l = 0
        for j in xrange(i, len(primes)):
            s += primes[j]
            l += 1
            if s in primes_:
                result[l].append(s)
            if s > 1000000:
                break

    return max(result.iteritems(), key=operator.itemgetter(0))[1][0]
Esempio n. 6
0
def solve():
    d = 1
    primes = []
    phi = None

    while True:
        for p in gen_primes():
            d *= p
            primes.append(p)
            phi = totient(d)
                        
            if phi / float(d-1) < LIMIT:
                if p > 2:
                    primes.pop()
                    d /= p
                    phi = totient(d)
                    break
                else:
                    return d
Esempio n. 7
0
def solve():
    count = 1
    for prime in gen_primes():
        if count == 10001:
            return prime
        count += 1
Esempio n. 8
0
def solve():
    total = 0
    for p in gen_primes(40000000):
        if chain_length(p) == 25:
            total += p
    return total
Esempio n. 9
0
def solve():
    primes = set(gen_primes(1000000))

    return len([x for x in primes if all(y in primes for y in rotations(x))])
Esempio n. 10
0
def solve():
    for p in gen_primes():
        if check_prime(p):
            return p
Esempio n. 11
0
from common import gen_primes

DIGITS = map(str, range(10))
PRIMES = set(gen_primes(1000000))


def check_prime(p):
    p = str(p)
    for d in set(p):
        replacements = [int(p.replace(d, new_d)) for new_d in DIGITS]
        replacements = filter(lambda x: len(str(x)) == len(p), replacements)
        replacements = filter(lambda x: x in PRIMES, replacements)
        if len(replacements) >= 8:
            return True


def solve():
    for p in gen_primes():
        if check_prime(p):
            return p


def main():
    print 'Solution:', solve()


if __name__ == '__main__':
    main()