Skip to content

Commit 2932fef

Browse files
Update nlargestprime.py
1 parent f4e28e9 commit 2932fef

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Python/n-digit-largestprime/nlargestprime.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from math import sqrt
44
MAX = 100000000
5-
prime = [True] * (MAX + 1)
5+
prime = [True] * (MAX + 1)
66

77
def SieveOfEratosthenes() :
88
for p in range(2, int(sqrt(MAX)) + 1) :
99
if (prime[p] == True) :
1010
for i in range(p * p, MAX + 1, p) :
1111
prime[i] = False
12-
12+
13+
#function to find largest prime number
1314
def largestPrime(d) :
1415
l = 10 ** (d - 1)
1516
r = (10 ** d) - 1
@@ -18,7 +19,8 @@ def largestPrime(d) :
1819
return i
1920
return -1
2021

22+
#driver code
2123
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

0 commit comments

Comments
 (0)