Prime Numbers
Prime Numbers Prime Numbers
3.2 Sieving 123 this number’s entry is also 3. Dividing by 3 again, we get 1337, whose entry is 7. Dividing by 7, we get 191, whose entry is 1. Thus 191 is prime and we have the prime factorization 12033 = 3 2 · 7 · 191. Factor tables predate, by far, the computer era. Extensive hand-computed factor tables were indispensable to researchers doing numerical work in number theory for many decades prior to the advent of electronic calculating engines. 3.2.4 Sieving to construct complete factorizations Again, at the cost of somewhat more space, but very little more time, one may adapt the sieve of Eratosthenes so that next to entry m is the complete prime factorization of m. One does this by appending the prime p to lists at locations p, 2p, 3p,..., p⌊N/p⌋. One also needs to sieve with the powers pa of primes p ≤ √ N,wherethepowerpadoes not exceed N. At each multiple of pa another copy of the prime p is appended. To avoid sieving with the primes √N,N in the interval , one can divide to complete the factorization. For example, say N = 20000; let us follow what happens to the entry m = 12033. Sieving by 3, we change the 1 at location 12033 to 3. Sieving by 9, we change the 3 at location 12033 to 3, 3. Sieving by 7, we change the entry to 3, 3, 7. At the end of sieving (which includes sieving with all primes up to 139 and higher powers of these primes up to 20000), we return to each location in the sieve and multiply the list there. At the location 12033, we multiply 3 · 3 · 7, getting 63. Dividing 63 into 12033, the quotient is 191, which is also put on the list. So the final list for 12033 is 3, 3, 7, 191, giving the complete prime factorization of 12033. 3.2.5 Sieving to recognize smooth numbers Using the sieve of Eratosthenes to get complete factorizations may be simplified and turned into a device to recognize all of the B-smooth numbers (see Definition 1.4.8) in [2,N]. We suppose that 2 ≤ B ≤ √ N. Perform the factorization sieve as in the above subsection, but with two simplifications: (1) Do not sieve with any p a where p exceeds B, and (2) if the product of the list at a location is not equal to that location number, then do not bother dividing to get the quotient. The B-smooth numbers are precisely those at locations that are equal to the product of the primes in the list at that location. To simplify slightly, we might multiply a running product at each location by p whenever p a hits there. There is no need to keep the lists around if we are interested only in picking out the B-smooth numbers. At the end of the sieve, those locations whose location numbers are equal to the entry in the location are the B-smooth numbers. For example, say B =10andN = 20000. The entry corresponding to 12033 starts as 1, and gets changed sequentially to 3, to 9, and finally to
124 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES 63. Thus 12033 is not 10-smooth. However, the entry at 12000 gets changed sequentially to 2, 4, 8, 16, 32, 96, 480, 2400, and finally 12000. Thus 12000 is 10-smooth. One important way of speeding this sieve is to do the arithmetic at each location in the sieve with logarithms. Doing exact arithmetic with logarithms involves infinite precision, but there is no need to be exact. For example, say we use the closest integer to the base-2 logarithm. For 12000 this is 14. We also use the approximations lg 2 ≈ 1 (this one being exact), lg 3 ≈ 2, lg 5 ≈ 2, lg 7 ≈ 3. The entry now at location 12000 gets changed sequentially to 1, 2, 3, 4, 5, 7, 9, 11, 13. This is close enough to the target 14 for us to recognize that 12000 is smooth. In general, if we are searching for B-smooth numbers, then an error smaller than lg B is of no consequence. One should see the great advantage of working with approximate logarithms, as above. First, the numbers one deals with are very small. Second, the arithmetic necessary is addition, an operation that is much faster to perform on most computers than multiplication or division. Also note that the logarithm function moves very slowly for large arguments, so that all nearby locations in the sieve have essentially the same target. For example, above we had 14 the target for 12000. This same number is used as the target for all locations between 2 13.5 and 2 14.5 , namely, all integers between 11586 and 23170. We shall find later an important application for this kind of sieve in factorization algorithms. And, as discussed in Section 6.4, sieving for smooth numbers is also crucial in some discrete logarithm algorithms. In these settings we are not so concerned with doing a perfect job sieving, but rather just recognizing most B-smooth numbers without falsely reporting too many numbers that are not B-smooth. This is a liberating thought that allows further speed-ups in sieving. The time spent sieving with a prime p in the sieve is proportional to the product of the length of the sieve and 1/p. In particular, small primes are the most time-consuming. But their logarithms contribute very little to the sum, and so one might agree to forgo sieving with these small primes, allowing a little more error in the sieve. In the above example, say we forgo sieving with the moduli 2, 3, 4, 5. We will sieve by higher powers of 2, 3, and 5, as well as all powers of 7, to recognize our 10smooth numbers. Then the running sum in location 12000 is 3, 4, 5, 9, 11. This total is close enough to 14 to cause a report, and the number 12000 is not overlooked. But we were able to avoid the most costly part of the sieve to find it. 3.2.6 Sieving a polynomial Suppose f(x) is a polynomial with integer coefficients. Consider the numbers f(1),f(2),...,f(N). Say we wish to find the prime numbers in this list, or to prepare a factor table for the list, or to find the B-smooth numbers in this list. All of these tasks can easily be accomplished with a sieve. In fact, we have already seen a special case of this for the polynomial f(x) =2x +1, when we
- Page 86 and 87: 72 Chapter 1 PRIMES! Cast this sing
- Page 88 and 89: 74 Chapter 1 PRIMES! 10 10 . The me
- Page 90 and 91: 76 Chapter 1 PRIMES! These numbers
- Page 92 and 93: 78 Chapter 1 PRIMES! Next, as for q
- Page 94 and 95: 80 Chapter 1 PRIMES! (see [Bach 199
- Page 96 and 97: 82 Chapter 1 PRIMES! If one invokes
- Page 98 and 99: 84 Chapter 2 NUMBER-THEORETICAL TOO
- Page 100 and 101: 86 Chapter 2 NUMBER-THEORETICAL TOO
- Page 102 and 103: 88 Chapter 2 NUMBER-THEORETICAL TOO
- Page 104 and 105: 90 Chapter 2 NUMBER-THEORETICAL TOO
- Page 106 and 107: 92 Chapter 2 NUMBER-THEORETICAL TOO
- Page 108 and 109: 94 Chapter 2 NUMBER-THEORETICAL TOO
- Page 110 and 111: 96 Chapter 2 NUMBER-THEORETICAL TOO
- Page 112 and 113: 98 Chapter 2 NUMBER-THEORETICAL TOO
- Page 114 and 115: 100 Chapter 2 NUMBER-THEORETICAL TO
- Page 116 and 117: 102 Chapter 2 NUMBER-THEORETICAL TO
- Page 118 and 119: 104 Chapter 2 NUMBER-THEORETICAL TO
- Page 120 and 121: 106 Chapter 2 NUMBER-THEORETICAL TO
- Page 122 and 123: 108 Chapter 2 NUMBER-THEORETICAL TO
- Page 124 and 125: 110 Chapter 2 NUMBER-THEORETICAL TO
- Page 126 and 127: 112 Chapter 2 NUMBER-THEORETICAL TO
- Page 128 and 129: 114 Chapter 2 NUMBER-THEORETICAL TO
- Page 130 and 131: Chapter 3 RECOGNIZING PRIMES AND CO
- Page 132 and 133: 3.1 Trial division 119 d =3; while(
- Page 134 and 135: 3.2 Sieving 121 3.2 Sieving Sieving
- Page 138 and 139: 3.2 Sieving 125 noticed that it was
- Page 140 and 141: 3.2 Sieving 127 } S = S \ (pS ∩ [
- Page 142 and 143: 3.3 Recognizing smooth numbers 129
- Page 144 and 145: 3.4 Pseudoprimes 131 } g =gcd(s, x)
- Page 146 and 147: 3.4 Pseudoprimes 133 Theorem 3.4.4.
- Page 148 and 149: 3.5 Probable primes and witnesses 1
- Page 150 and 151: 3.5 Probable primes and witnesses 1
- Page 152 and 153: 3.5 Probable primes and witnesses 1
- Page 154 and 155: 3.5 Probable primes and witnesses 1
- Page 156 and 157: 3.6 Lucas pseudoprimes 143 The Fibo
- Page 158 and 159: 3.6 Lucas pseudoprimes 145 Because
- Page 160 and 161: 3.6 Lucas pseudoprimes 147 use (3.1
- Page 162 and 163: 3.6 Lucas pseudoprimes 149 gcd(n, 2
- Page 164 and 165: 3.6 Lucas pseudoprimes 151 Theorem
- Page 166 and 167: 3.7 Counting primes 153 Label the c
- Page 168 and 169: 3.7 Counting primes 155 for b ≥ 2
- Page 170 and 171: 3.7 Counting primes 157 The heart o
- Page 172 and 173: 3.7 Counting primes 159 t =Im(s) ra
- Page 174 and 175: 3.7 Counting primes 161 Indeed, the
- Page 176 and 177: 3.8 Exercises 163 3.3. Prove that i
- Page 178 and 179: 3.8 Exercises 165 3.12. Show that a
- Page 180 and 181: 3.8 Exercises 167 3.28. Show that t
- Page 182 and 183: 3.9 Research problems 169 with W (n
- Page 184 and 185: 3.9 Research problems 171 3.50. The
3.2 Sieving 123<br />
this number’s entry is also 3. Dividing by 3 again, we get 1337, whose entry<br />
is 7. Dividing by 7, we get 191, whose entry is 1. Thus 191 is prime and we<br />
have the prime factorization<br />
12033 = 3 2 · 7 · 191.<br />
Factor tables predate, by far, the computer era. Extensive hand-computed<br />
factor tables were indispensable to researchers doing numerical work in<br />
number theory for many decades prior to the advent of electronic calculating<br />
engines.<br />
3.2.4 Sieving to construct complete factorizations<br />
Again, at the cost of somewhat more space, but very little more time, one<br />
may adapt the sieve of Eratosthenes so that next to entry m is the complete<br />
prime factorization of m. One does this by appending the prime p to lists at<br />
locations p, 2p, 3p,..., p⌊N/p⌋. One also needs to sieve with the powers pa of<br />
primes p ≤ √ N,wherethepowerpadoes not exceed N. At each multiple of<br />
pa another copy of the prime p is appended. To avoid sieving with the primes<br />
√N,N<br />
in the interval , one can divide to complete the factorization.<br />
For example, say N = 20000; let us follow what happens to the entry<br />
m = 12033. Sieving by 3, we change the 1 at location 12033 to 3. Sieving by<br />
9, we change the 3 at location 12033 to 3, 3. Sieving by 7, we change the entry<br />
to 3, 3, 7. At the end of sieving (which includes sieving with all primes up to<br />
139 and higher powers of these primes up to 20000), we return to each location<br />
in the sieve and multiply the list there. At the location 12033, we multiply<br />
3 · 3 · 7, getting 63. Dividing 63 into 12033, the quotient is 191, which is also<br />
put on the list. So the final list for 12033 is 3, 3, 7, 191, giving the complete<br />
prime factorization of 12033.<br />
3.2.5 Sieving to recognize smooth numbers<br />
Using the sieve of Eratosthenes to get complete factorizations may be<br />
simplified and turned into a device to recognize all of the B-smooth numbers<br />
(see Definition 1.4.8) in [2,N]. We suppose that 2 ≤ B ≤ √ N. Perform the<br />
factorization sieve as in the above subsection, but with two simplifications: (1)<br />
Do not sieve with any p a where p exceeds B, and (2) if the product of the list<br />
at a location is not equal to that location number, then do not bother dividing<br />
to get the quotient. The B-smooth numbers are precisely those at locations<br />
that are equal to the product of the primes in the list at that location.<br />
To simplify slightly, we might multiply a running product at each location<br />
by p whenever p a hits there. There is no need to keep the lists around if we<br />
are interested only in picking out the B-smooth numbers. At the end of the<br />
sieve, those locations whose location numbers are equal to the entry in the<br />
location are the B-smooth numbers.<br />
For example, say B =10andN = 20000. The entry corresponding to<br />
12033 starts as 1, and gets changed sequentially to 3, to 9, and finally to