Fast Method for Computing the Number of Primes Less than a Given

Fast Method for Computing the Number
Primes Less than a Given Limit
of
By David C. Mapes
Abstract. "Fast Method for Computing the Number of Primes Less Than a
Given Limit" describes three processes used during the course of calculation. In
the first part of the paper the author proves :
4>(x,a) =4>(x,D - <t>
(-,l)
\P2
/
-</>(-,
\PS
2)-4>(-,a-l
)
\Pa
)
where <f>(x,a) represents the number of numbers less than or equal to x and not
divisible by the first "a" primes. This identity is used to evaluate the formula
r(x) = 4>{x, a) + a — 1, a+l>
tt(\/x)
where resulting terms of the form
(p(x, a) are broken down still further by the previously described method, or
numerically evaluated using one or both of two other identities, the choice being
dependent on x and a .
Following the paper is a table of calculations made using this process which
gives the values of ir(x) for x at intervals of 10 million up to 1000 million, along
with the Riemann and the Chebyshev approximations for t(x) and the amount they
deviate from the true count.
1. Definitions and Notations.
■k(x): the number of primes less than or equal to x.
pa: the ath prime, (pi = 2).
ma:
[x]:
c:
c\ x:
c \ x:
S(x, a):
<p(x, a) :
4>(—x, a) :
Ps(x, a) :
Ps(—x,a):
P1P2 ■■ ■ Pa .
greatest integer ^x.
any integer.
c divides x.
c does not divide x.
set of all numbers ^x and prime to ma .
number of members of S(x, a).
equivalent to —<f>(x,a).
number of products of s primes belonging to S(x, a), Po(x, a) = 1.
equivalent
to —Ps(x, a).
Pi(x, a) :
by definition is ir(x) — a.
LegendreSum:
4>(x,a) = [x] — ^
[x/pi] +
X)
\x/piP,]
2. Formula Development.
(1)
H
[x/Pi Pi Pk] + • • •
Let:
Tk(x, a) m (-l)^+íl+-+fc-1[x/p?yi
• • • pS-1],
where k = 2a~1ßa^1+ 2°~2fr,_2+ • • • 20j30such that the ß's are either 1 or 0, thus
Received June 7, 1962.
179
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
180
DAVID C. MAPES
being the digits of k expressed in binary form and where 0 ^ k < 2a. Let us also
adopt: Tk(—x, a) = —Tk(x, a). Legendre's sum may be written in the following
order :
2«-l
(2)
<t>(x,a) = £
Tk(x, a).
k=0
Let M be an integer < 2a and let 2l be the highest power of 2 dividing M. Let
ilf+2«-l
(3)
y(M,x,a)
=
E
Tk(x,a).
k—M
Full understanding
(4)
of (3) should be clear from the identity:
4>(x, a) = To(x, a) + 7(20, x, a) + 7(2\ x, a) + ■• • + 7(2a_1, x, a),
which is (2) with (3) applied.
From ( 1) it follows that :
(5)
{sgn Tk(x, a)\k>0,2i]k = (_i)fc+*+i+-+"-i
and
(6)
| Tk(x, a) |ft>0,2q* = [x/p?+ip?+V
By substituting
• • ■ Pa"'1].
Tk(x, a) for a; and ¿ for a in (1) we get:
Tk>{Tk(x,a),i\
= sgn{Tk(x,a)](~l)ß0'+ßi'+-+ßi-1
X[\Tk(x,a)\/p{°'pß/
■•■p{1-»],
where fc' = 2i_1/3,'_i+ 2,'"2lsL2+ • • • + 2°/3o'and 0 ^ k'. When 21'| fc,we can substitute (5) and (6) into (7) giving:
(8)
Tk>{Tk(x, a), i]2i]k = Tk+k>(x, a).
By substituting
TM(x, a) for x and i for a in (2) we get
2»-i
2'-\
(9)
4>{Tu(x,a),i)
z
= Z
Tk.{TM(x,a),i\.
Using (8), (9) becomes
.M+2«-l
4>{TM(x,a),i}2<]M =
Z
1\(x, a)
k=M
and using (3) we have
(10)
y(M, x, a) = <v{TM(x,a), i\.
Now (4) becomes
<l>(x,a) = T0(x, a) + 4>{T2<>(x,
a), 0}
(11)
+ é{Tîi(x,a),
11 + ••■ + 4>{Ttß-i(x,a), a -l\.
By replacing x with TM(x, a) and a with i, we get
¿{TV*, a), ¿1 = To{TM(x, a), i] + <j>(T2o{TM(x,
a), i\, 0)
(12)
+ <t>(T2i{TM(x,a),i],
!) + ••■ + 4>(T2i-ATm(x, a),i],i
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
- 1).
FAST METHOD FOR COMPUTING NUMBER OF PRIMES
181
Using (1) to find T0{TM(x, a), i] and (8) in general, we get
<p{TM(x, a), i]ii\M = TM(x, a) + ó{TM+*>(x, a), 0}
(13)
+ <f>[TM+2i(x,a), 1} + • • • + <f>{TM+ii-i(x, a), i — 1¡.
We can now calculate <j>(x,a) by (13) setting <¡>(x,a) equal to 4>{T0(x, a), a] where
2° ¡ 0. In (13) TM(x, a) is computed by (1) while the remaining terms are computed by reapplication of (13) or, if reduced by (1) to a numerical expression of
<p(x, a), by any other method of computing <p(x, a).
3. Other Methods of Calculating <¡>(x,a). The following method for calculating
<t>(x,a) was developed by D. H. Lehmer [1]. Meissel's formula for finding ir(x) is a
special case of this method [1].
v—i
(14)
<t>(x,a) = X Ps(x, a),x < pj+i
where
Po(x, a) = 1,
Pi(x, a) = t(x)
P*(x,a)=
— a,
£
W(x/Vi) ~ (» - 1)},
Pa<Pi=xIPi
P3(x,a)
Z
Pa<Piúx/Pi
.
T,
PiéPjÁxIPiPj
{«(x/piPj) - (j - 1)}.
If V — 1 is greater than 3 this method of calculating 4>{x,a) may not be practical.
Also
(15)
4>(x, a) = c<f>(ma,a) + <f>(r,a)
where x = cma + r, \r\ ^ \ma , and a > 1. Hence c</>(ra0,a) can be calculated
using a table of the values for <j>(ma, a) and <j>(r,a) by (14) or (13).
4. Fast Method for Computing ic(x). From the above development
formulate the following procedure for computing ir(x). Use the formula:
(16)
we can
ir(x) = 4>(x, a) + a - 1
where pl+i ^ x ^ pa2. Place a limit on V in ( 14) such that <j>(x,a) is not computable
by (14) when pa+i ^ x. Now place a limit on a in ( 15) such that <t>(r,a) will always
be computable by (14) with its restriction V i£ 4. This means the value of a in (15)
must meet the requirement 1 < a ^ 6. With a limited table of primes, the larger
the better, we are prepared to compute ir(x).
Compute 4>(x, a) in (16) by (13) where the resulting term T0(x, a) is computed
by (1). The rest of the resulting terms from (13) considered as expressions of the
form 4>(x, a) are computed by (1) if a = 1, by (15), 0(r, o) being computed by
(14), if 1 < a ;£ 6, and by (14) or the reapplication of (13) if a > 6. In the latter
case 4>(x, a) is computed
the table of primes when
(13) are calculated using
calculation of <¡>(x,a) in
by (14) unless V > 4 or ir(x) is too large to be found in
2 ^ V ^ 4. The resulting terms from a reapplication of
the process used in calculating the resulting terms of the
(16).
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
182
DAVID C. MAPES
y = O; M= O; ! = o -tr (V~x~)
y: = y + THE COMPUTED
VALUE OF T m (x , o)
CAN0 fTM (x, a), ij
NO
BE CALCULATED BY
(14) OR (15)9
f IS SET SUCH THAT
-| m: = m-
21 I M AND 2'+l.
iM.
YES
y: = y +
THE COMPUTED VALUE
of«
{tm(x,0),;}
m: = M + 2 '
i IS SET SUCH THAT
2' / M AND 2'+l^-M
NO
1T( x) = y + o - I
We now introduce a system of order as an aid to our method of calculating ir(x).
At any point in our calculations we will have a number of terms calculated. Introducing y as the sum of these calculated terms, here is the system of order in flow
chart form.
The length of time necessary for the calculation of w(x) on the 709 using the
author's
program was:
t ~
t(x)
60z1OEl05Msec.
In the following table the "Li" function is Chebyshev's
and the "R" function is the Riemann approximation
R(x)
= £
approximation
n-ln(n)Li(xlln).
They are computed using
t •/ \
Li(x)
ii/i
\ . i
, (hi x)2 . (In xY ,
2X2!
3X3!
= y + In (In x) + In x + n w ¿, + ; w „, 4
»w-'+t +kiSV
+
where S„ = £i°°fc "•
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
+
(In x)7i
75 X 75!
(In a;)75
S76(75 X 75!)
for
FAST METHOD FOR COMPUTING NUMBER OF PRIMES
183
Although the table gives x only at intervals of 10 million, calculations have also
been made for x at intervals of 1 million, with the results listed in the same manner.
Values of t(x) for x (in millions) at 1, 2, ... ,10 checked with values obtained by
D. N. Lehmer [2]. The values of t(x) for the following values oî x (in millions)
checked with those listed by D. H. Lehmer [1, p. 386]: 20, 25, 33, 37, 40, 90, 100,
999, and 1000.
5. Acknowledgement. Work was performed under the auspices of the U. S.
Atomic Energy Commission. Formula construction was done with the aid of D. H.
Lehmer. Tables were computed using an IBM 709 at the Lawrence Radiation
Laboratory of the University of California.
Lawrence Radiation Laboratory
University of California
Livermore, California
1. D. H. Lehmer, Illinois J. Math., v. 3, no. 3, p. 381-388,1959.
2. D. N. Lehmer, List of Prime Numbers from 1 to 10,006,721, New York, Hafner Pub. Co.,
1956.
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
184
DAVID C. MAPES
Comparison of the Count of Primes with the Corresponding Values of the Formulas
of Chebyshevand Riemann at intervals of 10,000,000 up to 1,000,000,000.
r(x)
10000000
20000000
30000000
40000000
50000000
60000000
70000000
80000000
90000000
100000000
110000000
120000000
130000000
140000000
150000000
160000000
170000000
180000000
190000000
200000000
210000000
220000000
230000000
240000000
250000000
260000000
270000000
280000000
290000000
300000000
310000000
320000000
330000000
340000000
350000000
360000000
370000000
380000000
390000000
400000000
410000000
420000000
430000000
440000000
450000000
460000000
470000000
480000000
490000000
500000000
664579
1270607
1857859
2433654
3001134
3562115
4118064
4669382
5216954
5761455
6303309
6841648
7378187
7912199
8444396
8974458
9503083
10030385
10555473
11078937
11601626
12122540
12642573
13161544
13679318
14195860
14711384
15226069
15739663
16252325
16764521
17275206
17785475
18294605
18803526
19311288
19818405
20325373
20831210
21336326
21840713
22344479
22848050
23350555
23853038
24354548
24855718
25356424
25856368
26355867
Li(x)
664918
1270905
1858213
2434016
3001557
3562683
4118585
4670091
5217810
5762209
6303656
6842446
7378825
7912998
8445139
8975397
9503902
10030768
10556096
11079975
11602484
12123696
12643676
13162482
13680169
14196786
14712378
15226988
15740653
16253409
16765291
17276328
17786551
18295985
18804658
19312592
19819810
20326334
20832184
21337378
21841935
22345872
22849204
23351948
23854119
24355729
24856793
25357324
25857333
26356832
R(x)
664667
1270571
1857818
2433570
3001067
3562154
4118020
4669493
5217182
5761552
6302971
6841735
7378090
7912239
8444357
8974593
9503077
10029923
10555231
11079090
11601581
12122775
12642736
13161525
13679195
14195796
14711372
15225965
15739614
16252355
16764222
17275245
17785453
18294873
18803531
19311452
19818656
20325167
20831003
21336185
21840729
22344653
22847973
23350705
23852863
24354461
24855513
25356032
25856029
26355517
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
Li{x) -
R(x) -
ir(x)
r(x)
+339
+298
+354
+362
+423
+568
+88
-36
-41
-84
-67
+39
-44
+ 111
+228
+97
-338
+87
-97
+40
-39
+ 135
-6
-462
-242
+ 153
-45
+235
+ 163
-19
-123
-64
-12
-104
-49
+ 30
-299
+39
-22
+268
+5
+ 164
+251
-206
-207
-141
+ 16
+ 174
-77
+ 150
-175
-87
-205
-392
-339
-350
+521
+709
+856
+754
+347
+798
+638
+799
+743
+939
+819
+383
+623
+ 1038
+858
+ 1156
+ 1103
+938
+851
+ 926
+994
+919
+990
+ 1084
+770
+ 1122
+ 1076
+ 1380
+ 1132
+ 1304
+ 1405
+961
+974
+ 1052
+ 1222
+ 1393
+ 1154
+ 1393
+ 1081
+ 1181
+ 1075
+900
+965
+965
FAST METHOD FOR COMPUTING
w(x)
Li(x)
NUMBER
OF PRIMES
R(x)
Li(x) —
w(x)
510000000
520000000
530000000
540000000
550000000
560000000
570000000
580000000
590000000
600000000
610000000
620000000
630000000
640000000
650000000
660000000
670000000
680000000
690000000
700000000
710000000
720000000
730000000
740000000
750000000
760000000
770000000
780000000
790000000
800000000
810000000
820000000
830000000
840000000
850000000
860000000
870000000
880000000
890000000
900000000
910000000
920000000
930000000
940000000
950000000
960000000
970000000
980000000
990000000
1000000000
26854252
27352687
27850698
28348381
28845356
29342150
29838286
30334175
30829544
31324703
31819444
32313388
32807229
33300450
33793395
34286170
34778319
35270167
35761747
36252931
36743905
37234048
37724170
38213987
38703181
39192219
39680979
40169476
40658253
41146179
41634187
42121502
42608404
43095410
43581966
44067840
44553888
45039361
45524412
46009215
46494557
46979583
47463433
47947424
48431471
48915316
49398798
49881580
50364709
50847534
26855833
27354346
27852381
28349949
28847059
29343720
29839940
30335730
30831095
31326045
31820587
32314729
32808477
33301838
33794819
34287427
34779667
35271546
35763069
36254242
36745071
37235561
37725717
38215544
38705046
39194230
39683099
40171658
40659911
41147862
41635516
42122877
42609948
43096733
43583236
44069462
44555412
45041091
45526502
46011649
46496534
46981161
47465532
47949652
48433523
48917147
49400527
49883667
50366569
50849235
26854507
27353008
27851033
28348589
28845688
29342338
29838548
30334327
30829682
31324622
31819153
32313285
32807023
33300374
33793345
34285943
34778173
35270042
35761556
36252719
36743539
37234019
37724166
38213984
38703477
39192652
39681512
40170062
40658306
41146248
41633893
42121245
42608308
43095084
43581579
44067796
44553738
45039408
45524811
46009949
46494826
46979445
47463809
47947920
48431783
48915399
49398771
49881903
50364797
50847455
License or copyright restrictions may apply to redistribution; see http://www.ams.org/journal-terms-of-use
+ 1581
+ 1659
+ 1683
+ 1568
+ 1703
+ 1570
+ 1654
+ 1555
+ 1551
+ 1342
+ 1143
+ 1341
+ 1248
+ 1388
+ 1424
+ 1257
+ 1348
+ 1379
+ 1322
+ 1311
+ 1166
+ 1513
+ 1547
+ 1557
+ 1865
+2011
+2120
+2182
+ 1658
+ 1683
+ 1329
+ 1375
+ 1544
+ 1323
+ 1270
+ 1622
+ 1524
+ 1730
+2090
+2434
+ 1977
+ 1578
+ 2099
+2228
+2052
+ 1831
+ 1729
+2087
+ 1860
+ 1701
185