Skip to content

Finder Primes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions FindingPrimes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
-The sieve of Eratosthenes is an algorithm used to find prime numbers, less than or equal to a given value.
-Illustration: https://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif
'''
from math import sqrt
def SOE(n):
check = round(sqrt(n)) #Need not check for multiples past the square root of n

sieve = [False if i <2 else True for i in range(n+1)] #Set every index to False except for index 0 and 1

for i in range(2, check):
if(sieve[i] == True): #If i is a prime
for j in range(i+i, n+1, i): #Step through the list in increments of i(the multiples of the prime)
sieve[j] = False #Sets every multiple of i to False

for i in range(n+1):
if(sieve[i] == True):
print(i, end=" ")