Factorization and Prime Numbers
This is Lab 2 from Clint by Hugh Montgomery, edited by Elad Zelingher. All rights reserved to Hugh Montgomery.
The program FacTab produces a table of least prime divisors of odd numbers, up to . The values are calculated by dividing small primes into the numbers in the desired range, until the only numbers for which a least prime divisor has not been found are prime. Let be a given prime number. The least composite integer such that is the least prime factor of is . (In this connection, recall Problem 24. on p. 30 of NZM.) Thus if one is to prepare a table of least prime factors of integers in an interval , then it is useful to have on hand a table of all primes . In the case of FacTab, the intervals considered are of the form with . Since 31607 and 31627 are consecutive primes, and since
it suffices to have a table of primes through the prime 31607. Such a table of primes may be constructed as follows: Consider a sequence of 's and 's. Initially we take , and for all . We operate on this sequence so that eventually if is prime, otherwise. Start with , and while perform the following operations: Put . This is the least composite integer such that is still 1. Put . Replace by , and set . Replace by . Continue in this manner until . By examining the numbers , find the least integer such that and . Then is the least prime number greater than . Replace by , and start over. This method of generating primes is known as the Sieve of Eratosthenes. It suffices to sieve only to , since 173 is the largest prime . FacTab constructs a table of small primes in this way when the program is first loaded, with one modification: Since the even numbers are immediately eliminated, FacTab saves time and memory by applying the sieve only to the odd integers.
Problem 1
Use FacTab to view the least prime factors of the odd numbers in an interval. You will note that the least prime factor of numbers of the form display a certain pattern. Describe this pattern, and prove that it persists.
Problem 2
Can you find any other patterns similar to the one noted above?
Problem 3
For , how many primes lie between and ? How do these numbers compare with ?
Problem 4
For several values of and (with small compared with ), count the primes between and , and compare the result with .
Problem 5
How many primes lie between 20831330 and 20831530? By changing the value of Start, determine whether this is typical of similar intervals in this vicinity. For a report of a more extensive study of the gaps between primes, see D. Shanks, On Maximal Gaps between Successive Primes, Math. Comp. 18 (1964), 646-651.
Problem 6
For how many integers is the least prime factor of greater than 2? Greater than 3? Than 5? Than 7? How do these numbers increase with ? Formulate a conjecture concerning the asymptotic behavior. Can you prove your conjecture? (Theorem 8.8(e) and Theorem 8.29 of NZM are relevant here.)
Problem 7
A prime number is called a twin prime if is also prime. Repeat Problem 3 above, but this time counting only twin primes. How do the counts compare with ? Do you conjecture that there are infinitely many twin primes, or do you conjecture that there are only finitely many?
Problem 8
The program Factor determines the canonical factorization of an integer by trial division. Suppose that prime factors have been found, and removed, leaving an integer yet to be factored. If then we are done. If then is prime, and we are done in this case also. Otherwise, we divide into . If then is prime, and we repeatedly divide by until no longer divides the remaining number. Then we replace by and repeat the process. To save time, after powers of 2 have been removed, only odd are considered. Further savings can be obtained by noting that after removing powers of 2 and of 3 it suffices to consider of the forms .
Factor takes this a step further: After powers of , and have been removed, only those of the eight forms , , , , , , , are considered. Thus is replaced by after only 8 trial divisions. This method is in principle slightly wasteful, because it would be enough to consider prime values of , but in practice it seems to take longer to generate a table of primes. (Try it, if you like to write programs.) Instead of generating a table of primes, one could construct a permanent file listing primes, and then call the needed primes from that file, but this seems to take still longer.
Use FacTab to find the largest prime for . Apply Factor to each of these nine primes, and note the time required to perform the calculations. Is the time roughly ? What values of do you observe?
Problem 9
Apply Factor to each of the numbers for . In some of these cases, you will tire of waiting for a complete resolution. To interrupt the program, simply press a key, and note how the program reports its partial results.
Problem 10
Apply factor to 20 randomly-chosen numbers . Make a record of these numbers, and note which ones are square-free. What proportion of them are square-free? How close is this proportion to ? How many integers are not divisible by 4? How many are not divisible by 9? How many by neither 4 nor 9? The proportion of for which and tends to a limit as tends to infinity. What is this limit?
Can you guess how this limit would change if we also require that ? (See Theorems 8.25 and 8.29 of NZM.)
Problem 11
The program GetNextP yields the least prime greater than a given number , provided that . For in this range, GetNextP uses the same sieving procedure as found in FacTab. For larger values of , the program GetNextP locates the least integer that is likely to be prime. That is, the interval contains no prime number and is "probably" prime (in the sense that it passes several strong pseudoprime tests; this is discussed on pp. 77, 78 of NZM).
Use GetNextP to find the least prime , for several . How are the differences distributed? What is their mean? If you like to program, you could conduct a larger study, and a more detailed statistical analysis.
The asyptotic situation remains a matter of conjecture, but it is expected that as tends to infinity, the mean lies between and . Also, for any fixed , it is predicted that the proportion of integers such that tends to as tends to infinity.
Problem 12
Write a program that deletes from a given sequence of integers those that are divisible by the square of a prime. In this way, count the number of square-free integers in various short intervals, and also the number of square-free integers not exceeding .
In Theorem 8.25 of NZM it is shown that the number of square-free integers not exceeding is where . (The -notation is defined on p. 365 of NZM.) It is conjectured that the error term here is actually for any . Although such a strong upper bound for the magnitude of the error term has not yet been proved, it is known that the error term does achieve the order of infinitely often. Does the numerical evidence generated by your program support the stronger conjecture? Still less is known concerning the variation in the number of square-free numbers in short intervals.