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.

130 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES<br />

Next we reduce the number P modulo every label in T by creating<br />

a “remainder tree” (see [Bernstein 2004e]). In general, a remainder tree<br />

P mod T for a given integer P and a given product tree T is the corresponding<br />

tree in which each label in T being replaced by its remainder when it is divided<br />

into P . This relabeling is achieved by replacing the label R at the root of T<br />

with P mod R, and then working toward the leaves, each entry is replaced with<br />

the remainder after dividing this entry into the new label of its parent. We<br />

illustrate with the product tree T formed from 1001,...,1008 and the number<br />

P = 9699690 found in our first product tree. We may evidently convert each<br />

asterisk in T to P .<br />

<br />

✟❍9699690<br />

✟<br />

✟ ❍❍❍❍❍9699690<br />

✟<br />

✟<br />

✟<br />

9699690<br />

❅<br />

❅<br />

❅<br />

❅<br />

672672<br />

❅<br />

0 ❅330<br />

❅636582 ❅<br />

680❅46 600420<br />

❅<br />

435❅844 ❅564186 ❅<br />

266❅714 Remainder tree P mod T<br />

For each x that we are examining for smoothness, the corresponding leaf<br />

value in the remainder tree is P mod x. Take this residue, sequentially square<br />

modulo x the requisite number of times, and at last take the gcd of the final<br />

result with x. A value of 0 signifies that x is smooth over the primes in P ,<br />

and a nonzero value is itself the largest divisor of x that is smooth over the<br />

primes in P . Here is pseudocode for this beautiful algorithm.<br />

Algorithm 3.3.1 (Batch smoothness test (Bernstein)). We are given a finite<br />

set X of positive integers and a finite set P of primes. For each x ∈X,this<br />

algorithm returns the largest divisor of x composed of primes from P.<br />

1. [Compute product trees]<br />

Compute the product tree for P;<br />

Set P as the product of the members of P;<br />

// We find P at the root of the product tree for P.<br />

Compute the product tree T for X , but only for products at most P ;<br />

2. [Compute remainder tree]<br />

Compute the remainder tree P mod T ; // Notation described in text.<br />

3. [Find smooth parts]<br />

Set e as the least positive integer with max X≤22e; for(x ∈X){<br />

Find P mod x in the remainder tree P mod T ;<br />

// No additional mod calculation is necessary.<br />

r = P mod x;<br />

s = r2e mod x; // Compute s by sequential squaring and reducing.

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

Saved successfully!

Ooh no, something went wrong!