def is_circular_prime(number): """if number is a circular prime, return True, else False. >>> is_circular_prime(37) True >>> is_circular_prime(197) True >>> is_circular_prime(101) False >>> is_circular_prime(123) False """ num_string = str(number) for i in range(len(num_string)): if not util_euler.is_prime(int(num_string)): return False num_string = rotate(num_string) return True
def sum_of_primes_below(n): sum_primes = 2 for i in range(3, n, 2): if is_prime(i): sum_primes += i return sum_primes
import util_euler if __name__ == "__main__": truncatable_primes = [] number = 10 while True: number += 1 if all(util_euler.is_prime(int(str(number)[i:])) for i in range(len(str(number)))): if all(util_euler.is_prime(int(str(number)[:-i])) for i in range(1,len(str(number)))): truncatable_primes.append(number) print(truncatable_primes) if len(truncatable_primes) == 11: break print("sum of truncatable primes is {0}".format(sum(truncatable_primes)))
import util_euler if __name__ == "__main__": LIMIT = 999 A = 0 B = 0 MAX_N = 0 for a in range(-LIMIT, LIMIT + 1): for b in range(-LIMIT, LIMIT + 1): n = 0 consecutive_prime_count = 0 while True: formula = n * n + a * n + b if not util_euler.is_prime(formula): break consecutive_prime_count += 1 n += 1 if consecutive_prime_count > MAX_N: A, B, MAX_N = a, b, consecutive_prime_count print("a:{0} b:{1} max_n:{2}".format(A, B, MAX_N)) print("answer:{0}".format(A * B))
import util_euler if __name__ == "__main__": count = 0 numbers_on_diagonal = 1 primes_on_diagonal = 0 number = 1 layer = 1 while True: number += 2 * layer count += 1 if util_euler.is_prime(number): primes_on_diagonal += 1 numbers_on_diagonal += 1 if count % 4 == 0: if primes_on_diagonal / numbers_on_diagonal < 0.1: side_length = 2 * layer + 1 break count = 0 layer += 1 print("answer: {0}".format(side_length))
import util_euler from math import sqrt if __name__ == "__main__": number = 3 while True: odd_divisors = util_euler.find_divisors(number, proper=True) odd_divisors.remove(1) for d in odd_divisors: if d % 2 == 0: odd_divisors.remove(d) if not all((number / d) % 2 == 0 for d in odd_divisors): if all(not util_euler.is_prime(number - (i ** 2) * 2) for i in range(int(sqrt(number)))): answer = number break number += 2 print("answer: {0}".format(answer))