def solve(): for comp in count(3, 2): if is_prime(comp): continue holds = False for s in xrange(1, int(math.sqrt(comp / 2 + 1) + 1)): diff = comp - 2 * s * s if is_prime(diff): holds = True break if not holds: return comp
def solve3(): ps = primes(1, UPPER_PRIME) for l in xrange(len(ps), 1, -1): for i in xrange(len(ps) - l + 1): p = sum(ps[i:i + l]) #print '%s -> %s' % (ps[i:i+l], p) if p < 1000000 and is_prime(p): return p
def solve3(): ps = primes(1, UPPER_PRIME) for l in xrange(len(ps), 1, -1): for i in xrange(len(ps) - l + 1): p = sum(ps[i:i+l]) #print '%s -> %s' % (ps[i:i+l], p) if p < 1000000 and is_prime(p): return p
def solve(): ps = primes(1, UPPER_PRIME) for l in xrange(len(ps), 1, -1): s = sum(ps[-l:]) for i in xrange(len(ps) - l, -1, -1): #print s if s < 1000000 and is_prime(s): return s s = s + ps[i - 1] - ps[i + l - 1]
def solve(): for d in range(7, 0, -1): # optimization: skip 9- and 8-digit numbers for candidate in permutations(reversed(range(1, d + 1))): p = reduce(lambda t, x: 10 * t + x, candidate) if is_prime(p): return p