aboutsummaryrefslogtreecommitdiffstats
path: root/10001prime.py
diff options
context:
space:
mode:
Diffstat (limited to '10001prime.py')
-rw-r--r--10001prime.py52
1 files changed, 28 insertions, 24 deletions
diff --git a/10001prime.py b/10001prime.py
index ecaa8cd..bc51d49 100644
--- a/10001prime.py
+++ b/10001prime.py
@@ -1,30 +1,34 @@
-import PIL, math
+import PIL
+import math
+
+# Problem 7 - 10,001st prime
+
+# returns a list of every prime up to a certain number
-#Problem 7 - 10,001st prime
-#returns a list of every prime up to a certain number
def listprimes(number):
- primes = []
- if (number <=1):
- return [1]
- a = [1] * number
- a[0]=0
- a[1]=0#1 and 0 are not prime
- ##Sieve of eratosthenes
- for i in range(2,int(math.ceil(math.sqrt(number)))):
- if(a[i]==1):
- j = i**2 #cross out all the multiples of i, starting with its square
- while(j < number):
- a[j] = 0
- j+=i
-
- for k in range(2, number):
- #is prime
- if(a[k]==1):
- primes.append(k)
- return primes
+ primes = []
+ if (number <= 1):
+ return [1]
+ a = [1] * number
+ a[0] = 0
+ a[1] = 0 # 1 and 0 are not prime
+ # Sieve of eratosthenes
+ for i in range(2, int(math.ceil(math.sqrt(number)))):
+ if(a[i] == 1):
+ j = i**2 # cross out all the multiples of i, starting with its square
+ while(j < number):
+ a[j] = 0
+ j += i
+
+ for k in range(2, number):
+ # is prime
+ if(a[k] == 1):
+ primes.append(k)
+ return primes
+
out_list = listprimes(1000000)
-#print(out_list)
-#return 10,001th prime factor
+# print(out_list)
+# return 10,001th prime factor
print(out_list[10000])