Skip to content

Commit 3e41fbe

Browse files
AthaSSiNOmkarPathak
authored andcommitted
Added an efficient method to find primes (#8)
1 parent 8906b98 commit 3e41fbe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CompetitiveProgramming/HackerEarth/Basics_Of_Input_Output/P04_PrimeNumber.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# Constraints
1313
# 1 <= N <=1000
1414

15+
import math
16+
1517
userInput = int(input())
16-
for i in range(2, userInput):
18+
for i in range(2, userInput + 1):
1719
check = 0
18-
for j in range(2, i):
20+
for j in range(2, int(math.sqrt(i))+ 1):
1921
if i % j == 0:
2022
check = 1
2123
break

0 commit comments

Comments
 (0)