def efficient_quad_primes(max_coeff=1000): list_primes = list(x for x in range(2, 1000) if is_prime(x)) coefficients = 0, 0 current_max = 0 for a in list(-x for x in list_primes) + list_primes: for b in list(-x for x in list_primes) + list_primes: n = 0 print(a, b) quad_func = quad(a, b) val = quad_func(n) while val > 1 and is_prime(val): n += 1 val = quad_func(n) print(n) if n > current_max: current_max = n coefficients = a, b return coefficients, current_max
import numpy as np from core import is_prime primes = np.loadtxt("100000.txt", dtype=int).flatten() primes = primes[primes < 1000000] consecutive_sums = {} for i in range(primes.size): for j in range(i+1, primes.size): s = sum(primes[i:j]) n = j - i if s > 1000000: break consecutive_sums[n] = s for key in reversed(sorted(consecutive_sums)): num = consecutive_sums[key] if is_prime(num): print(num)
""" 10001st prime """ from core import is_prime n = 3 count = 2 lim = 10001 while True: n += 2 if is_prime(n): print n count += 1 if count == lim: break
from core import is_prime print(sum(x for x in range(3, 2000000) if is_prime(x)) + 2)
def test_is_prime(): print('is %s prime? %s' % (10, core.is_prime(10))) print('is %s prime? %s' % (11, core.is_prime(11))) print('is %s prime? %s' % (100, core.is_prime(100)))
def get_max_prime_factor(factors): for factor in reversed(factors): if core.is_prime(factor): return factor return None
def max_pandigital_prime(n_digits=5): pandigitals = possible_prime_pandigitals(n_digits) for p in reversed(list(pandigitals)): if is_prime(p): return p
def test_is_prime_15(self): self.assertEquals(is_prime(15), False)
def test_is_prime_1219(self): self.assertEquals(is_prime(1219), False)
def test_is_prime_9(self): self.assertEquals(is_prime(9), False)
def test_is_prime_401(self): self.assertEquals(is_prime(401), True)
def test_is_prime_907(self): self.assertEquals(is_prime(907), True)
def test_is_prime_13(self): self.assertEquals(is_prime(13), True)
def test_is_prime_2(self): self.assertEquals(is_prime(2), True)