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.2 Sieving 121<br />

3.2 Sieving<br />

Sieving can be a highly efficient means of determining primality and factoring<br />

when one is interested in the results for every number in a large, regularly<br />

spaced set of integers. On average, the number of arithmetic operations spent<br />

per number in the set can be very small, essentially bounded.<br />

3.2.1 Sieving to recognize primes<br />

Most readers are likely to be familiar with the sieve of Eratosthenes. In its<br />

most common form it is a device for finding the primes up to some number<br />

N. StartwithanarrayofN− 1 “ones,” corresponding to the numbers from<br />

2toN. The first one corresponds to “2,” so the ones in locations 4, 6, 8,<br />

and so on, are all changed to zeros. The next one is in the position “3,” and<br />

we read this as an instruction to change any ones in locations 6, 9, 12, and<br />

so on, into zeros. (Entries that are already zeros in these locations are left<br />

unchanged.) We continue in this fashion. If the next entry one corresponds<br />

to “p,” we change to zero any entry one at locations 2p, 3p, 4p, and so on.<br />

However, if p is so large that p2 >N, we may stop this process. This exit<br />

point can be readily detected by noticing that when we attempt to sieve by p<br />

there are no changes of ones to zeros to be made. At this point the one entries<br />

in the list correspond to the primes not exceeding N, while the zero entries<br />

correspond to the composites.<br />

In passing through the list 2p, 3p, 4p, and so on, one starts from the initial<br />

number p and sequentially adds p until we arrive at a number exceeding N.<br />

Thus the arithmetic operations in the sieve are all additions. The number of<br />

steps in the sieve of Eratosthenes is proportional to <br />

N/p, wherep runs<br />

over primes. But<br />

<br />

p≤N<br />

N<br />

p<br />

p≤N<br />

= N ln ln N + O(N); (3.1)<br />

see Theorem 427 in [Hardy and Wright 1979]. Thus, the number of steps<br />

needed per number up to N is proportional to ln ln N. It should be noted<br />

that ln ln N, though it does go to infinity, does so very slowly. For example,<br />

ln ln N

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

Saved successfully!

Ooh no, something went wrong!