Primality Test | Set 1 (Introduction and School Method) - GeeksforGeeks
Primality Test | Set 1 (Introduction and School Method)
Given a positive integer, check if the number is prime or not. A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples of first few prime numbers are {2, 3, 5,
Examples:
Input: n = 11 Output: true Input: n = 15 Output: false Input: n = 1 Output: false
School Method
A simple solution is to iterate through all numbers from 2 to n-1 and for every number check if it divides n. If we find any number that divides, we return false.
Read full article from Primality Test | Set 1 (Introduction and School Method) - GeeksforGeeks
Nice blog!! Best explanation with appropriate links. Thanks for sharing.
ReplyDeleteCheers,
http://www.flowerbrackets.com/java-program-to-find-prime-number/