Update
This commit is contained in:
parent
e8579f4b86
commit
f920115b91
13 changed files with 1776 additions and 1715 deletions
2
prime.md
2
prime.md
|
@ -84,6 +84,8 @@ There also exists a term **pseudoprime** -- it stands for a number which is not
|
|||
|
||||
**Prime gaps**: statistically gaps between consecutive primes increase. The size of the gaps themselves make another number sequence that starts like this 1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 14, 4, 6, 2, 10, 2, 6, 6, 4, 6, 6, 2, 10, 2, 4, 2, 12, 12, 4, 2, 4, 6, 2, 10, 6, 6, 6, 2, 6, 4, 2, 10, 14, 4, 2, 4, 14, 6, 10, 2, 4, 6, 8, 6, 6, 4, 6, 8, 4, 8, 10.
|
||||
|
||||
**[Fun](fun.md) with primes**: thanks to their interesting, mysterious and [random](randomness.md) nature, primes can be played around -- of course, you can examine them mathematically, which is always fun, but you can also play sort of [games](game.md) with them. For example the prime race: you make two teams of primes, one that gives 1 modulo 4, the other one that gives 3; then you go prime by prime and add points to each team depending on which one the prime falls in; the interesting thing is that team 3 is almost always in lead just by a tiny amount (this is known as Chebyshev bias, only after 2946 primes team 1 gets in the lead for a while, then at 50378 etc.). Similar thing can be done by evaluating the Mobius function: set total sum to 0, then go number by number and if it only has unique prime factors, add 1 if the number of those factors is even, otherwise subtract 1 -- see how the function behaves. Of course you can go crazy, make primes paint pictures or compose [music](music.md) -- people also like to do this with digits of numbers, e.g. those of [pi](pi.md) or [e](e.md).
|
||||
|
||||
## Algorithms
|
||||
|
||||
**Primality test**: testing whether a number is a prime is quite easy and not computationally difficult (unlike factoring the number). A [naive](naive.md) algorithm is called *trial division* and it tests whether any number from 2 up to the tested number divides the tested number (if so, then the number is not a prime, otherwise it is). This can be [optimized](optimization.md) by only testing numbers up to the [square root](sqrt.md) (including) of the tested number (if there is a factor greater than the square root, there is also another smaller than it which would already have been tested). A further simple optimization is to to test division by 2, 3 and then only numbers of the form 6q +- 1 (other forms are divisible by either 2 or 3, e.g 6q + 4 is always divisible by 2). Further optimizations exist and for maximum speed a [look up table](lut.md) may be used for smaller primes. A simple [C](c.md) function for primality test may look e.g. like this:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue