Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are different methods to verify if a number is prime, but one common method is the trial division method:

  1. Start with the number n that you want to test for primality.
  2. Find the square root of n and round it up to the nearest integer. Call this number m.
  3. Check if n is divisible by 2 or 3. If it is, then n is not prime.
  4. Start with i=5 and check if n is divisible by i or i+2. Continue this process up to m. If none of the numbers in this interval divide n, then n is prime.

For example, to test if 23 is prime:

  1. Start with n=23.
  2. The square root of 23 is about 4.8, so m=5.
  3. 23 is not divisible by 2 or 3.
  4. Check if 23 is divisible by 5 or 7. Since neither 5 nor 7 divide 23, we can conclude that 23 is prime.