#!C:\Python33\python.exe #https://projecteuler.net/problem=10 from Prime import prime3 prime3.prime_gen(2000000) print(sum(prime3.prime_list))
def prod_of_coefficients(self): return self.a * self.b def consecutive_primes(self): count = 0 fun = lambda x: x**2 + self.a * x + self.b result = fun(count) while result > 1 and prime3.is_prime(result): count += 1 result = fun(count) return count print(datetime.now().time()) prime3.prime_gen(1000) fixed_prime_list = list(prime3.prime_list) record = 0 record_holder = 0 def inner_loop(a, b): q = Quad(a, b) c = q.consecutive_primes() global record, record_holder if c > record: record = c record_holder = q.prod_of_coefficients() for a in range(-1000, 1000+1): for prime in fixed_prime_list:
#!C:\Python33\python.exe #https://projecteuler.net/problem=35 from Prime.prime3 import prime_gen, prime_list from bisect import bisect_left upto = 1000000 prime_gen(upto) count = 0 while prime_list: prime = prime_list[0] prime_str = str(prime) prime_len = len(prime_str) rotation_iter = range(1, prime_len) is_circular = True related_primes = set() for rotation in rotation_iter: prime_str = prime_str[-1] + prime_str[:-1] prime_int = int(prime_str) prime_index = bisect_left(prime_list, prime_int) try: assert prime_list[prime_index] == prime_int except: is_circular = False break related_primes.add(prime_int) related_primes.add(prime) if not is_circular: del prime_list[0] continue related_primes.add(prime)