Skip to content

Commit 0e6ca0f

Browse files
committed
Adding comments for understanding
1 parent e3055b1 commit 0e6ca0f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

primeNumbers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,28 @@
77

88

99
def is_number_prime(number):
10+
"""
11+
Function which checks whether the number is a prime number or not
12+
:param number: integer - to be checked for prime-ness
13+
:return: boolean - true if prime, else false
14+
"""
15+
16+
"""
17+
This is the main logic behind reducing the numbers to check for as factors
18+
if N = a * b; where a<=b and a,b C (1, N)
19+
then, a * b >= a*a;
20+
which leads to => a*a <= N
21+
=> a <= sqrt(N)
22+
Hence checking only till the square root of N
23+
"""
1024
upper_lim = Math.floor(Math.sqrt(number)) + 1
1125
is_prime = True if number != 1 else False
1226

1327
for i in range(2, upper_lim):
1428
if number % i == 0:
1529
is_prime = False
1630
break
31+
# The moment there is a divisor of 'number', break the iteration, as the number is not prime
1732

1833
return is_prime
1934

0 commit comments

Comments
 (0)