File tree 1 file changed +4
-9
lines changed
1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
Implementation of Sieve of Eratosthenes algorithm to generate all the primes upto N.
3
3
4
- Reference : https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
5
-
6
4
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.
11
9
"""
12
10
13
11
from math import sqrt ,ceil
@@ -20,6 +18,3 @@ def generate_primes(n):
20
18
bool_array [j ] = False # and mark them as False
21
19
primes = [i for i in range (n + 1 ) if bool_array [i ]] # return all numbers which are marked as True
22
20
return primes
23
-
24
- if __name__ == "__main__" :
25
- print (generate_primes (50 ))
You can’t perform that action at this time.
0 commit comments