10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.1 Trial division 119<br />

d =3;<br />

while(d 2 ≤ N) {<br />

while(d|N) {<br />

N = N/d;<br />

F = F∪{d};<br />

}<br />

d = d +2;<br />

}<br />

if(N == 1) return F;<br />

return F∪{N};<br />

After 3, primes are either 1 or 5 (mod 6), and one may step through the<br />

sequence of numbers that are 1 or 5 (mod 6) by alternately adding 2 and 4 to<br />

the latest number. This is a special case of a “wheel,” which is a finite sequence<br />

of addition instructions that may be repeated indefinitely. For example, after<br />

5, all primes may be found in one of 8 residue classes (mod 30), and a wheel<br />

that traverses these classes (beginning from 7) is<br />

4, 2, 4, 2, 4, 6, 2, 6.<br />

Wheels grow more complicated at a rapid rate. For example, to have a wheel<br />

that traverses the numbers that are coprime to all the primes below 30, one<br />

needs to have a sequence of 1021870080 numbers. And in comparison with<br />

thesimple2, 4 wheel based on just the two primes 2 and 3, we save only little<br />

more than 50% of the trial divisions. (Specifically, about 52.6% of all numbers<br />

coprime to 2 and 3 have a prime factor less than 30.) It is a bit ridiculous<br />

to use such an ungainly wheel. If one is concerned with wasting time because<br />

of trial division by composites, it is much easier and more efficient to first<br />

prepare a list of the primes that one will be using for the trial division. In the<br />

next section we shall see efficient ways to prepare this list.<br />

3.1.3 Practical considerations<br />

It is perfectly reasonable to use trial division as a primality test when n is<br />

not too large. Of course, “too large” is a subjective quality; such judgment<br />

depends on the speed of the computing equipment and how much time you are<br />

willing to allow a computer to run. It also makes a difference whether there is<br />

just the occasional number you are interested in, as opposed to the possibility<br />

of calling trial division repeatedly as a subroutine in another algorithm. On a<br />

modern workstation, and very roughly speaking, numbers that can be proved<br />

prime via trial division in one minute do not exceed 13 decimal digits. In one<br />

day of current workstation time, perhaps a 19-digit number can be resolved.<br />

(Although these sorts of rules of thumb scale, naturally, according to machine<br />

performance in any given era.)<br />

Trial division may also be used as an efficient means of obtaining a partial<br />

factorization n = FR as discussed above. In fact, for every fixed trial division<br />

bound B ≥ 2, at least one quarter of all numbers have a divisor F that is

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!