def get_optimal_coefficients(): a_b_combos = a_b_gen(range(-999, 1000), prime_gen(max_val=1000)) max_max_consecutive_prime, associated_prod_a_b = max( (max_consecutive_prime(a, b), a * b) for a, b in a_b_combos ) return associated_prod_a_b
def find_smallest_counter(): curr_comp = 9 while True: primes = [i for i in prime_gen(max_val=curr_comp + 1)] if curr_comp not in primes and not any( is_square((curr_comp - p) / 2) for p in primes): return curr_comp curr_comp += 2
def find_smallest_counter(): curr_comp = 9 while True: primes = [i for i in prime_gen(max_val=curr_comp + 1)] if curr_comp not in primes and not any(is_square((curr_comp - p)/2) for p in primes): return curr_comp curr_comp += 2
def sum_primes_less_than(n): total_sum = 0 primes = prime_gen() next_prime = next(primes) while next_prime < n: total_sum += next_prime next_prime = next(primes) return total_sum
def find_longest_cons_prime_sum(below_num): '''See function name :param below_num: INT search for consecutives below this number :yields: TUPLE(INT primes with sum of consecutive primes, INT n consecutive) ''' primes_below_num = [i for i in prime_gen(max_val=below_num)] max_sum = 0 max_len = 0 curr_result = (max_sum, max_len) n_primes_below_num = len(primes_below_num) for i in range(n_primes_below_num - 1, -1, -1): for j in range(i-1, -1, -1): candidate = sum(primes_below_num[j:i+1]) curr_len = i - j + 1 if candidate > below_num: break elif candidate in primes_below_num[i+1:]: max_sum, max_len = curr_result if curr_len > max_len: curr_result = (candidate, curr_len) return curr_result
def find_longest_cons_prime_sum(below_num): '''See function name :param below_num: INT search for consecutives below this number :yields: TUPLE(INT primes with sum of consecutive primes, INT n consecutive) ''' primes_below_num = [i for i in prime_gen(max_val=below_num)] max_sum = 0 max_len = 0 curr_result = (max_sum, max_len) n_primes_below_num = len(primes_below_num) for i in range(n_primes_below_num - 1, -1, -1): for j in range(i - 1, -1, -1): candidate = sum(primes_below_num[j:i + 1]) curr_len = i - j + 1 if candidate > below_num: break elif candidate in primes_below_num[i + 1:]: max_sum, max_len = curr_result if curr_len > max_len: curr_result = (candidate, curr_len) return curr_result
def all_4_digit_primes(): return [i for i in prime_gen(max_val=10000) if i >= 1000]
def main(): max_num = 1000000 primes = set(i for i in prime_gen(max_num)) print(sum(i for i in primes if is_trunctable(i, primes) and i > 7))