File tree 1 file changed +15
-0
lines changed 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 7
7
8
8
9
9
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
+ """
10
24
upper_lim = Math .floor (Math .sqrt (number )) + 1
11
25
is_prime = True if number != 1 else False
12
26
13
27
for i in range (2 , upper_lim ):
14
28
if number % i == 0 :
15
29
is_prime = False
16
30
break
31
+ # The moment there is a divisor of 'number', break the iteration, as the number is not prime
17
32
18
33
return is_prime
19
34
You can’t perform that action at this time.
0 commit comments