def run(): maximum_index = 0 maximum = 0 num_list = [] P = [i for i in xrange(2, 1000000) if is_probable_prime(i)] for p in P: num_list.append(0) for i in xrange(len(num_list)): num_list[i] += p if num_list[i] in P and num_list[i] < 1000000: if maximum_index < len(num_list) - i: maximum_index = len(num_list) - i maximum = num_list[i] if num_list[-1] >= 1000000 or p > 4000: return maximum if num_list[0] > 1000000: del num_list[0]
from itertools import product from eulertools import is_probable_prime for n in set([i[0]*i[1] for i in product(range(3, 1000, 2), repeat=2)]): i = 0 detect = True while True: i += 1 if 2 * pow(i, 2) > n: break remainder = n - (2 * pow(i, 2)) if remainder >= 2 and is_probable_prime(remainder): detect = False if detect: print n break
#!/usr/bin/python # Euler Project Problem 41 """Benchmark Intel Core2 Duo CPU P8400 @ 2.26GHz real 0m0.028s user 0m0.028s sys 0m0.000s """ from eulertools import is_probable_prime from itertools import permutations for p in reversed([int(''.join(n)) for n in permutations('1234567')]): if is_probable_prime(p): ans = p break print 'Answer to problem 41:', ans