1
Algorithm to check whether the given number is Prime or not. Test: Let p be the given number. Find a whole number nearly greater than . Let k > Test whether p is divisible by any prime number less than k. If yes, p is not a prime. Otherwise, p is prime. Example: Is 391 a prime? Solution: Here p = 391 Clearly 20 > Prime numbers less than 16 are 2, 3, 5, 7, 11, 13, 17 and 19. We find that 391 is divisible by 17. So, it is not a prime.

Algorithm to Check Whether the Given Number is Prime or Not

Embed Size (px)

Citation preview

Page 1: Algorithm to Check Whether the Given Number is Prime or Not

Algorithm to check whether the given number is Prime or not.

Test:

Let p be the given number. Find a whole number nearly greater than .Let k > Test whether p is divisible by any prime number less than k. If yes, p is not a prime. Otherwise, p is prime.

Example:Is 391 a prime?

Solution:Here p = 391Clearly 20 > Prime numbers less than 16 are 2, 3, 5, 7, 11, 13, 17 and 19.We find that 391 is divisible by 17.So, it is not a prime.