def prime_cut_right(n): if n < 10: return is_prime(n) cut = int(str(n)[:-1]) if is_prime(cut): return prime_cut_right(cut) return False
def prime_cut_left(n): if n < 10: return is_prime(n) cut = int(str(n)[1:]) if is_prime(cut): return prime_cut_left(cut) return False
def find_largest_prime_factor(number=DEFAULT_INPUT): if is_prime(number): return number largest = 1 i = 2 while i * i <= number: if number % i == 0 and is_prime(i): largest = i i += 1 return largest
def compute_smallest_evenly_divisible_number(ceiling=DEFAULT_INPUT): result = 1 i = 2 while i <= ceiling: if is_prime(i): powered_prime = i while powered_prime * i <= ceiling: powered_prime *= i result *= powered_prime i += 1 return result
def sum_prime_numbers_up_to_n(n=DEFAULT_INPUT): if n < 2: return 0 sum = 2 if n > 2: i = 3 while i < n: if is_prime(i): sum += i i += 2 return sum
def find_nth_prime_number(n=DEFAULT_INPUT): if n == 0: return None if n == 1: return 2 latest_prime = 3 if n > 2: for _ in range(3, n + 1): current = latest_prime + 2 while not is_prime(current): current += 2 latest_prime = current return latest_prime
from math import sqrt from euler_common import is_prime def digit_rotations(n): s = list(str(n)) result = [] for i in range(len(s)): s.append(s[0]) del s[0] result.append(int(''.join(s))) return result count = 0 for n in range(1000000): is_circular = True for r in digit_rotations(n): if not is_prime(r): is_circular = False break if is_circular: count += 1 print count
from euler_common import is_prime best_l = best_p = 0 for a in range(-999, 1000): for b in range(-999, 1000): count = 0 n = 0 while n * n + a * n + b > 0 and is_prime(n * n + a * n + b): n += 1 if n > best_l: best_p = a * b best_l = n print best_p
from __future__ import print_function, division from euler_common import is_prime side_length = 1 end = 1 n_prime_diagonals = 0 n_diagonals = 1 while True: side_length += 2 for _ in range(1, 5): end += side_length - 1 n_diagonals += 1 if is_prime(end): n_prime_diagonals += 1 if 100 * n_prime_diagonals // n_diagonals < 10: break print(side_length)
from euler_common import is_prime from math import sqrt num = 600851475143 root = sqrt(num) i = 1 sum = [] while i < root: i += 1 if num % i == 0: if is_prime(i): sum.append(i) if is_prime(num / i): sum.append(num / i) print max(sum)
def prime_cut_left(n): if n < 10: return is_prime(n) cut = int(str(n)[1:]) if is_prime(cut): return prime_cut_left(cut) return False def prime_cut_right(n): if n < 10: return is_prime(n) cut = int(str(n)[:-1]) if is_prime(cut): return prime_cut_right(cut) return False n = 7 # 2, 3, 5, 7 don't count count = 0 total = 0 # We are told only 11 exist while count < 11: n += 2 if is_prime(n) and prime_cut_left(n) and prime_cut_right(n): count += 1 total += n print total
def f(p): for l in range(len(p), 0, -1): for s in range(0, len(p) - l): n = sum(p[s:s + l]) if is_prime(n): return n
from euler_common import is_prime n = 1 # Starts at 2, 1 added in loop n_prime = 1 while n_prime <= 10001: n += 1 if is_prime(n): n_prime += 1 print n
from euler_common import is_prime total = 0 i = 3 while i < 2000000: if is_prime(i): total += i i += 2 # Add 2, 2 is the only even prime print total + 2