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.

120 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES<br />

greater than B and composed solely of primes not exceeding B; see Exercise<br />

3.4.<br />

Trial division is a simple and effective way to recognize smooth numbers,<br />

or numbers without large prime factors, see Definition 1.4.8.<br />

It is sometimes useful to have a “smoothness test,” where for some<br />

parameter B, one wishes to know whether a given number n is B-smooth,<br />

that is, n has no prime factor exceeding B. Trial division up to B not only<br />

tells us whether n is B-smooth, it also provides us with the prime factorization<br />

of the largest B-smooth divisor of n.<br />

The emphasis in this chapter is on recognizing primes and composites,<br />

and not on factoring. So we leave a further discussion of smoothness tests to<br />

a later time.<br />

3.1.4 Theoretical considerations<br />

Suppose we wish to use trial division to completely factor a number n into<br />

primes. What is the worst case running time? This is easy, for the worst case is<br />

when n is prime and we must try as potential divisors the numbers up to √ n.<br />

If we are using just primes as trial divisors, the number of divisions is about<br />

2 √ n/ ln n. If we use 2 and the odd numbers as trial divisors, the number of<br />

divisions is about 1√<br />

1<br />

2 n. If we use a wheel as discussed above, the constant 2<br />

is replaced by a smaller constant.<br />

So this is the running time for trial division as a primality test. What is its<br />

complexity as an algorithm to obtain the complete factorization of n when n is<br />

composite? The worst case is still about √ n, for just consider the numbers that<br />

are the double of a prime. We can also ask for the average case complexity for<br />

factoring composites. Again, it is almost √ n, since the average is dominated<br />

by those composites that have a very large prime factor. But such numbers are<br />

rare. It may be interesting to throw out the 50% worst numbers and compute<br />

the average running time for trial division to completely factor the remaining<br />

numbers. This turns out to be nc ,wherec =1/(2 √ e) ≈ 0.30327; see Exercise<br />

3.5.<br />

As we shall see later in this chapter and in the next chapter, the problem<br />

of recognizing primes is much easier than the general case of factorization. In<br />

particular, we have much better ways than trial division to recognize primes.<br />

Thus, if one uses trial division as a factorization method, one should augment<br />

it with a faster primality test whenever a new unfactored portion of n is<br />

discovered, so that the last bit of trial division may be skipped when the<br />

last part turns out to be prime. So augmenting trial division, the time to<br />

completely factor a composite n essentially is the square root of the second<br />

largest prime factor of n.<br />

Again the average is dominated by a sparse set of numbers, in this case<br />

those numbers that are the product of two primes of the same order of<br />

magnitude; the average being about √ n. But now throwing out the 50% worst<br />

numbers gives a smaller estimate for the average of the remaining numbers.<br />

It is nc ,wherec≈0.23044.

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

Saved successfully!

Ooh no, something went wrong!