def sum_of_primes(max): ''' Find the sum of all primes below the range. ''' list = euler.generate_primes(max_prime=2000000) return sum(list)
def new_solution(m): largest = 1 primes = generate_primes(greatest=sqrt_floor(m)) for p in primes: if m % p == 0: largest = p return largest
def nth_prime(n): ''' produces a list of primes, returns nth prime ''' l = euler.generate_primes(n) return l[n-1]
#!/usr/bin/env python """ Problem 010: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. """ from euler import generate_primes N = 2000000 print(sum(generate_primes(N)))
def is_factorized_n_distinct_primes(n, x, primes): factors = distinct_primes_factors(x, primes) return len(factors) == n def find_n_consecutive_ints(n, primes, start, stop): x = start while x < stop: #check if is_factorized_n_distinct_primes(n, x, primes): num = 1 y = x while is_factorized_n_distinct_primes(n, y+1, primes): y += 1 num += 1 top = y if num < n: y -= n - 1 while is_factorized_n_distinct_primes(n, y, primes) and y < x: y += 1 num += 1 x = top if num >= n: return top - n + 1 x += n if __name__ == '__main__': primes = generate_primes(n=4000) print('done generating primes') print(find_n_consecutive_ints(4,primes,2,1000000))