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.

118 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES<br />

3.1.2 Trial division<br />

Trial division is the method of sequentially trying test divisors into a number<br />

n so as to partially or completely factor n. We start with the first prime, the<br />

number 2, and keep dividing n by 2 until it does not go, and then we try the<br />

next prime, 3, on the remaining unfactored portion, and so on. If we reach a<br />

trial divisor that is greater than the square root of the unfactored portion, we<br />

may stop, since the unfactored portion is prime.<br />

Here is an example. We are given the number n = 7399. We trial divide<br />

by 2, 3, and 5 and find that they are not factors. The next choice is 7. It<br />

is a factor; the quotient is 1057. We next try 7 again, and find that again it<br />

goes, the quotient being 151. We try 7 one more time, but it is not a factor<br />

of 151. The next trial is 11, and it is not a factor. The next trial is 13, but<br />

this exceeds the square root of 151, so we find that 151 is prime. The prime<br />

factorization of 7399 is 7 2 · 151.<br />

It is not necessary that the trial divisors all be primes, for if a composite<br />

trial divisor d is attempted, where all the prime factors of d have previously<br />

been factored out of n, then it will simply be the case that d is not a factor<br />

when it is tried. So though we waste a little time, we are not led astray in<br />

finding the prime factorization.<br />

Let us consider the example n = 492. We trial divide by 2 and find that<br />

it is a divisor, the quotient being 246. We divide by 2 again and find that<br />

the quotient is 123. We divide by 2 and find that it does not go. We divide<br />

by 3, getting the quotient 41. We divide by 3, 4, 5 and 6 and find they do<br />

not go. The next trial is 7, which is greater than √ 41, so we have the prime<br />

factorization 492 = 2 2 · 3 · 41.<br />

Now let us consider the neighboring number n = 491. We trial divide by<br />

2, 3, and so on up through 22 and find that none are divisors. The next trial<br />

is 23, and 23 2 > 491, so we have shown that 491 is prime.<br />

To speed things up somewhat, one may exploit the fact that after 2, the<br />

primes are odd. So 2 and the odd numbers may be used as trial divisors. With<br />

n = 491, such a procedure would have stopped us from trial dividing by the<br />

even numbers from 4 to 22. Here is a short description of trial division by 2<br />

andtheoddintegersgreaterthan2.<br />

Algorithm 3.1.1 (Trial division). We are given an integer n > 1. This<br />

algorithm produces the multiset F of the primes that divide n. (A “multiset”<br />

is a set where elements may be repeated; that is, a set with multiplicities.)<br />

1. [Divide by 2]<br />

F = {}; // The empty multiset.<br />

N = n;<br />

while(2|N) {<br />

N = N/2;<br />

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

}<br />

2. [Main division loop]

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

Saved successfully!

Ooh no, something went wrong!