File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Sieve Of Eratosthenes:
2
+ The sieve of eratosthenes is one of the most efficient way to find all
3
+ the prime numbers upto the number `n`
4
+
5
+ for more reference(https://www.geeksforgeeks.org/sieve-of-eratosthenes/)
6
+ """
7
+
8
+ #importing `math` module which will be used later
9
+ import math
10
+
11
+ #specify upto where you have to find the prime numbers
12
+ n = int (input ("Enter the range : " ))
13
+
14
+ #`arr` is a boolean list that contains `n+1` `False` entries
15
+ arr = [False ]* (n + 1 )
16
+
17
+ #loop upto the square root of the range `n`
18
+ for i in range (2 ,int (math .sqrt (n ))+ 1 ):
19
+ if arr [i ] == False :
20
+ for j in range (i * i , n + 1 , i ):
21
+ #making the entry `True` for all entries whose index is the multiple
22
+ arr [j ] = True
23
+
24
+ #after the loop exits, all the entry that are prime numbers
25
+ #are marked as `False`
26
+
27
+ #printing all the prime numbers
28
+ for i in range (2 ,n ):
29
+ if arr [i + 1 ] == False :
30
+ print (i + 1 )
You can’t perform that action at this time.
0 commit comments