def p46(): primes = set(list_primes(10**6)) n = 3 while True: if n not in primes: found = False for p1 in list_primes(n): if is_perfect_square((n - p1) // 2): found = True break if not found: return n n += 2
def p49(): primes = list_primes(10000) set_primes = set(primes) for p in primes: for k in range(2, (10000 - p) // 2 + 1, 2): if p != 1487 and p + k in set_primes and p + 2 * k in set_primes and ispermutation( p, p + k) and ispermutation(p, p + 2 * k): answer = str(p) + str(p + k) + str(p + 2 * k) return answer
from p7 import list_primes if __name__ == "__main__": N = 10**6 primes = list_primes(N) set_primes = set(primes) max_j = -1 for i in range(len(primes)): j = 1 consecutive_sum = sum(primes[i:(i + j)]) while consecutive_sum < N and i + j <= len(primes): if consecutive_sum in set_primes and j > max_j: max_j = j answer = consecutive_sum j += 1 consecutive_sum = sum(primes[i:(i + j)]) print(answer)
from p3 import isprime from p7 import list_primes def left_truncate(n, r): return int(str(n)[r:]) def right_truncate(n, r): return int(str(n)[:-r]) if __name__ == "__main__": list_p = list_primes(10**6) numbers = [] for p in list_p: for r in range(1, len(str(p))): new_p1 = left_truncate(p, r) new_p2 = right_truncate(p, r) if not isprime(new_p1) or not isprime(new_p2): break elif r == len(str(p)) - 1: numbers.append(p) print(sum(numbers))
from p7 import list_primes if __name__ == "__main__": list_p = list_primes(2 * 10**6) print(sum(list_p))