File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Python/n-digit-largestprime Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
from math import sqrt
4
4
MAX = 100000000
5
- prime = [True ] * (MAX + 1 )
5
+ prime = [True ] * (MAX + 1 )
6
6
7
7
def SieveOfEratosthenes () :
8
8
for p in range (2 , int (sqrt (MAX )) + 1 ) :
9
9
if (prime [p ] == True ) :
10
10
for i in range (p * p , MAX + 1 , p ) :
11
11
prime [i ] = False
12
-
12
+
13
+ #function to find largest prime number
13
14
def largestPrime (d ) :
14
15
l = 10 ** (d - 1 )
15
16
r = (10 ** d ) - 1
@@ -18,7 +19,8 @@ def largestPrime(d) :
18
19
return i
19
20
return - 1
20
21
22
+ #driver code
21
23
if __name__ == "__main__" :
22
- N = int (input ("Enter N digit" ))
23
- SieveOfEratosthenes ()
24
- print (largestPrime (N ))
24
+ N = int (input ("Enter N digit" )) #input
25
+ SieveOfEratosthenes () #call to SieveOfEratosthenes() function
26
+ print (largestPrime (N )) #call to function and output
You can’t perform that action at this time.
0 commit comments