n
is called a prime number if the only positive integers that divide n
are 1 and n
itself.
Integers that are not prime are called composite.
Here are the first few prime numbers:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, ...To check if a number
n>2
is prime, repeatedly divide it by numbers m
, where 2≤m≤½×n
.
The number is prime if none of the remainders is zero.