def main(): primes = [str(p) for p in list_of_primes(10000)] s_primes = set(str(p) for p in list_of_primes(1000000)) primes = [p for p in primes if p[-1] != "2" or p[-1] != "5"] con = [p1+p2 for p1 in primes for p2 in primes] con = [c for c in con if c in s_primes] print con
def main(): answers = [] primes = list_of_primes(1000000) primes = [str(p) for p in primes] master = set(primes) left = lambda x: all(i in master for i in truncate_left(x)) right = lambda x: all(i in master for i in truncate_right(x)) primes = [p for p in primes if not "0" in p and not "4" \ in p and not "6" in p and not "8" in p and not "5" in p] primes = [p for p in primes if p[0] != "9" or p[-1] != "9"] primes = [p for p in primes if left(p) and right(p)] primes = [p for p in primes if len(p) > 1] primes = [int(p) for p in primes] print sum(primes)
#!/usr/bin/env python from util import list_of_primes primes = list_of_primes(1000000) sprimes = set(primes) def main(): max_chain = 0 num = 0 for i in range(len(primes)): j = i while j < len(primes): n = sum(primes[i:j]) if n > 1000000: break if n in sprimes and j-i > max_chain: max_chain = j-i num = n j+=1 print max_chain, num if __name__ == '__main__': main()
def main(): print sum(list_of_primes(2000000))
from util import list_of_primes, digits primes = set(str(p) for p in list_of_primes(1000000)) def count(number): return set(d for d in number[:-1] if number[:-1].count(d) > 1) def replace_digit(prime,digit,i): return prime[:-1].replace(digit,i) + prime[-1] def all_possible(prime,d): return [replace_digit(prime,d,str(i)) for i in range(10) if replace_digit(prime,d,str(i)) in primes] def main(): for p in primes: for digit in count(p): chain = all_possible(p,digit) if len(chain) == 8: print chain exit()
#!/usr/bin/env python from util import list_of_primes primes = [str(p) for p in list_of_primes(1000000)] def rotate(str): for i in range(len(str)): str = str[1:] + str[0] yield str def remove_evens(): temp_primes = [] for s in primes: if "2" not in s and "4" not in s and "6" not in s and "8"\ not in s and "0" not in s and "5" not in s: temp_primes.append(s) return temp_primes def main(): temp_primes = [] for s in remove_evens(): for r in rotate(s): if r not in primes: break else: temp_primes.append(s) print len(temp_primes) + 2
def main(): print list_of_primes(200000)[10000]
def test_extend_list_of_primes(): L = util.list_of_primes(1500000) P = util.extend_list_of_primes(3000000, L)