def main(): LIMIT = 10**6 primes = sieve_of_eratosthenes(LIMIT) cumulative_sums = [2 for i in primes] for i in range(1, len(cumulative_sums)): cumulative_sums[i] = primes[i] + cumulative_sums[i-1] result = 0 number_of_primes = 0 for i in range(0, len(cumulative_sums)): for j in range(i - (number_of_primes + 1), -1, -1): sum_consecutive_primes = cumulative_sums[i] - cumulative_sums[j] # sum_consecutive_primes increases as the inner loop advances. If # the difference is already too large, we can break the loop, since # it will only grow larger if sum_consecutive_primes > LIMIT: break if is_prime(sum_consecutive_primes): number_of_primes = i - j result = sum_consecutive_primes print(result) return
def main(): result = 0 for i in sieve_of_eratosthenes(10**6): rotations = get_rotations(i) if len(list(filter(lambda x : is_prime(x), rotations))) == len(rotations): result+=1 print(result)
def main(): current_sieve_limit = 100000 sieve = sieve_of_eratosthenes(current_sieve_limit) n = 2*3*4*5 - 1 while True: n += 1 # Re-compute the sieve if n > current_sieve_limit: current_sieve_limit *= 2 sieve = sieve_of_eratosthenes(current_sieve_limit) if (len(prime_factors(n, sieve)) == 4 and len(prime_factors(n+1, sieve)) == 4 and len(prime_factors(n+2, sieve)) == 4 and len(prime_factors(n+3, sieve)) == 4): print(n) break
def main(): max_run = 0 product = 0 b_set = sieve_of_eratosthenes(1000) # With b = 2 for a in range(-998, 998, 2): this_run = prime_run(a, 2) if this_run > max_run: max_run = this_run product = a*2 # With b != 2 for a in range(-999, 999, 2): for b in b_set[1:]: this_run = prime_run(a, b) if this_run > max_run: max_run = this_run product = a*b print(product)
def main(): print(sum(sieve_of_eratosthenes(limit-1)))