Skip to content

Commit

Permalink
Added problem 7 solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanidris committed Feb 25, 2012
1 parent bb27cc2 commit 9ab62b0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions euler/problem7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy

LIM = 10 ** 6
N = 10 ** 9
P = 10001
primes = []
p = 2

#By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

#What is the 10 001st prime number?

def check_primes(a, p):
#2. Sieve out multiples of p
a = a[a % p != 0]

return a

for i in xrange(3, N, LIM):
#1. Create a list of consecutive integers
a = numpy.arange(i, i + LIM, 2)

while len(primes) < P:
a = check_primes(a, p)
primes.append(p)

p = a[0]

print len(primes), primes[P-1]

0 comments on commit 9ab62b0

Please sign in to comment.