How to check whether N is a prime number?
Let’s play with prime
Wait…….!
What is a Prime number?
A prime number is a whole number which is only divisible by the 1 and the number itself.
Let’s see the conversation between prime numbers and consonant numbers.
Prime number: Hey..! consonant number.
Consonant number: Hey..! prime number. Can you tell who can divide you?
Prime number: The first natural number ‘1’ can divide me.
Consonant number: Wow! ‘1’ can divide me also. Can any other divide you?
Prime number: Not possible…….. Other than ‘1’ only I can divide my self.
Consonant number: That’s Great… Ok Bye … Prime number.
Prime Number: Bye..!
Procedure to check Prime Number
STEP 1: Return False, if N = 0 or N = 1
STEP 2: Return True, if N = 2 or N = 5
STEP 3: Return False, if unit digit of N is ‘5’ or ‘0’. Use Bitwise operators to reduce calculation complexity.
STEP 4: Return False, if N is an Even Number.
STEP 5: Take the square root of N. If any of the prime numbers less than or equal to the Square root of N divides N properly, then return False. Else return True.
Python Program
C Program
Hurray…! Hope it will help you.