def truncatable_primes(): primes = sieve_of_erastothenes(750000) primes_set = set(primes) truncatable = set() for i in primes: if i < 10: truncatable.add(i) continue if is_truncatable_prime(i, primes_set): truncatable.add(i) truncatable.remove(2) truncatable.remove(3) truncatable.remove(5) truncatable.remove(7) return truncatable
def concat_prime_perms(): all_primes = sieve_of_erastothenes(9999) primes = set([i for i in all_primes if i > 999]) for i in range(3333, 1000, -1): for j in range(1000, 9999): hits = list() for k in range(0, 3): curr = j + k * i if curr > 9999: break if curr in primes: hits.append(curr) if len(hits) >= 3 and hits[0] != 1487: if permutations(hits): return "".join('{0}'.format(n) for n in hits) return "- not found -"
def most_consecutive_prime_sum(max): primes = sieve_of_erastothenes(max) prime_count = len(primes) p_set = set(primes) longest_term_count = 0 ret = 0 for i in range(prime_count): sum = 0 term_count = 0 for j in range(i, prime_count): sum += primes[j] if sum > max: break term_count += 1 if term_count > longest_term_count and sum in p_set: longest_term_count = term_count ret = sum return ret
def smallest_comp_not_sum_of_prime_and_double_square(): limit = 10000 primes = sieve_of_erastothenes(limit) odds = [] for odd in range(3, limit, 2): if odd in primes: continue found = False for prime in primes: if prime >= odd: break n = odd - prime if is_twice_a_square(n): found = True break if not found: return odd return -1
def circular_primes(max): primes = sieve_of_erastothenes(max) all_numbers = [False] * (max + 1) for p in primes: all_numbers[p] = True circular_primes = [] for p in primes: all_primes = True for perm in permute_cyclically(str(p)): n = int(perm) if not all_numbers[n]: all_primes = False break if all_primes: circular_primes.append(p) return circular_primes
def main(): n = 2000000 print ("Sum of primes below {}: {}".format(n, sum(sieve_of_erastothenes(n))))