Primes

=**Useful stuff about primes: [ref: [|wiki/Prime_number]]**=


 * 1) Any number can be represented as a product of primes numbers unique up to ordering.
 * 2) 1 is not a prime number since it can be written as many times in the product for the same number indefinitely.
 * 3) The simplest and slowest method to test for primality is by trial division by iterating from 2 to sqrt(n) and checking divisibility.
 * 4) Particularly fast methods are available for numbers of special forms, such as [|Mersenne number]
 * 5) There are [|infinitely many] primes, as [|demonstrated by Euclid] around 300 BC.
 * 6) There is no known useful formula that sets apart all of the prime numbers from composites. However, the distribution of primes, that is to say, the statistical behaviour of primes in the large, can be modeled. The first result in that direction is the [|prime number theorem], proven at the end of the 19th century, which says that the [|probability] that a given, randomly chosen number //n// is prime is inversely [|proportional] to its number of digits, or to the [|logarithm] of //n//.
 * 7) While a simple method, trial division quickly becomes impractical for testing large integers because the number of possible factors grows too rapidly as //n// increases. According to the prime number theorem explained below, the number of prime numbers less than [[image:http://upload.wikimedia.org/math/d/4/3/d435c6dd92f3b3430d735f360cba0ec9.png caption="sqrt{n}"]] is approximately given by [[image:http://upload.wikimedia.org/math/b/a/8/ba8701ac0159757bde57a915a9a39443.png caption="sqrt{n} / ln(sqrt{n})"]], so the algorithm may need up to this number of trial divisions to check the primality of //n//. For //n// = 1020, this number is 450 million—too large for many practical applications.
 * 8) Modern primality tests for general numbers //n// can be divided into two main classes, [|probabilistic] (or "Monte Carlo") and [|deterministic algorithms]. The former merely "test" whether //n// is prime in the sense that they declare //n// to be (definitely) composite or "[|probably prime]", the latter meaning that //n// may or may not be a prime number. Composite numbers that do pass a given primality test are referred to as [|pseudoprimes]. For example, [|Fermat's primality test] relies on [|Fermat's little theorem]. This theorem says that for any prime number //p// and any integer //a// not divisible by //p//, //a////p// − 1 − 1 is divisible by //p//. Thus, if //a////n// − 1 − 1 is not divisible by //n//, //n// cannot be prime. However, //n// may be composite even if this divisibility holds. In fact, there are infinitely many composite numbers //n// that pass the Fermat primality test for every choice of //a// that is coprime with //n// ([|Carmichael numbers]), for example //n// = 561.