Skip to content

Commit cb0f2e8

Browse files
committed
Update sieve_of_eratosthenes.py
1 parent f30f609 commit cb0f2e8

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

misc/sieve_of_eratosthenes.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""
22
Implementation of Sieve of Eratosthenes algorithm to generate all the primes upto N.
33
4-
Reference : https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
5-
64
Algorithm :
7-
* We have a list of numbers from 1 to N.
8-
* Initially, all the numbers are marked as primes.
9-
* We go to every prime number in the list (<= N ^ 1/2) and mark all the multiples
10-
of this prime number which are bigger than the number itself as non-primes.
5+
* We have a list of numbers from 1 to N.
6+
* Initially, all the numbers are marked as primes.
7+
* We go to every prime number in the list (<= N ^ 1/2) and mark all the multiples
8+
of this prime number which are bigger than the number itself as non-primes.
119
"""
1210

1311
from math import sqrt,ceil
@@ -20,6 +18,3 @@ def generate_primes(n):
2018
bool_array[j] = False # and mark them as False
2119
primes = [i for i in range(n+1) if bool_array[i]] # return all numbers which are marked as True
2220
return primes
23-
24-
if __name__ == "__main__":
25-
print(generate_primes(50))

0 commit comments

Comments
 (0)