Internat. J. Math.
VOL. 18 NO. 3 (1995) 539-544
ON THE
K-thEXTENSION OF THE SIEVE OF ERATOSTHENES
ANTONIO R.QUESADA
Department
of Mathematical Sciences, The University ofAkron,Akron, OH44325-4002R
quesa@VM1.cc.UAkron.edu(Received November 19, 1993 andinrevised form March 28, 1994)
ABSTRACT. TheSieveofEratosthenes has been recently extendedbyexcluding the multiples of2, 3, and 5 from the initial set, and finding the additiverules that give the positions of the multiplesofthe remaining primes. We generalizethese results. Foragiven k welet the initial set Sk consists of natural numbers relatively prime to the first k primes, and find the rules governing the positions of the multiples of the remaining elements.
KEY
WORDSAND
PHRASES. Prime numbers, sieve, tables of primes, algorithms.1992 AMS SUBJECT
CLASSIFICATION CODES.
llA41, 11-04, llY16.1. INTRODUCTION.
One of several algorithms from the Greeks that,has survived the test of time, due to its simplicity and efficiency, is the Sieve of Eratosthenes. Given an initial set of positive integers S
{2,
3,4,...,N},
the prime numbers inS canbe found iteratively byfirst crossing out all the multiples of 2 larger than 2 inS;
then, in each subsequent step, the multiples of the smallest remaining number p not previously considered are crossed out. The process continues whilep
<N. Itshouldbenoted that only prime numbersareusedtosieve, and that the multiples of anynumberparep unitsapart.The advent of computers and the electronic transmission of information, with encrypting and testing techniques based on large primes, explains the enormous attention that the prime numbers havereceived duringthe last twenty-fiveyears. The search for efficient algorithms to generate large tables of primes have produced impressive results such as Benelloum
[1],
Mairson
[2],
and Pritchard[3].
Several improvements have been made to the Sieve by reducing the size of the initial set and by avoiding some duplication in the removal process.In
this paper,wewilljustifyandgeneralize these simplifications of the Sieve,which may proveto beof particularinterest inparallelprocessing.The original algorithmcanbe readily improved, to what wewillcall thefirst extension, by first letting the initial set, denoted
Sa,
consistof only odd numbers, and then crossing out the multiples of p fromp2
on, starting with p 3. We remark that, in this first extension, the multiples ofany number p canstill be foundbycounting, since their positions inSa
arestill p540 A. R. QUESADA
,,fitsapart. Iu the olh’st ieference tothe Sievecommonly available inEnglish, Nichomacus
[4]
states that Erato.thenswas awareofthis ideaofstartingwithonlyoddnuml)ers, andmade use ofit. In g’neral,no distinction isfound in theliteraturebetween theoriginalSieve and the first extension (ofI,hmth
[5]).
In 1989, Xuedoug Luo
[6]
obtaimd a second extension of the Sieve ly also re,noving the ,nultiples of threef,o,n the initialset. denotedS.
Three yearslater, a third extensionwasfound byQuesada[7]
by furtherremoving the multiples offive fromthe setSa.
Ineachextension, thereductiou in size of the new initial set produces a change in the position of the re,naining elements; thus, for example 29 changes f,’om being the fourteenth element in
S
to the ninthelement of
S,
and the seventh inSa.
Asaresult, the positionsofconsecutivemultiplesof any givennunber p areno longerp units apart. Instead, they canbe obtained by adding cyclically the elements ofapredetermined finiteset ofdifferences, dependingonp, whosesize varies from oneextension toanother. Forinstance, thepositionsofthe nultiplesof7can be obtained inS
by successively adding the elements of the set
{9,5},
while in Sa the corresponding set of differencesbetween theremaining multiples of 7is{12,7,4,7,4,7,12,3}.
2. NOTATIONAND BASIC DEFINITIONS.
We now generalize this process for obtaining the prime numbers less than or equal to a
given
N.
First we denote theinitial setbyS,
that is, the set obtainedfrom S by removing the multiples of the first k prime numbers. Then, for any p inS
we determine the rulesgovern the positionsofthemultiplesof p in
Sk.
k
Let p, p,-.., p,,.., denote the sequence of prime numbers, and let ’, 1-Ipi, k >1. We
i=l
denote by
C
the set of positive integers relatively prime and less than h,, i.e., we letCk
{c:+[
c<rk, (c,rk)= 1}. The cardinality m, ofC,
is given by the Euler totientfunction, thatisweletm,
[C,[ (b(rk)=
i=llI (Pi-1).
In order toobtain the k-th extension wechoose the set of candidates
Sk
so that it contains just those positive integers less than or equal to N and relatively prime to w,, thus we letS,
{n n qh,+c<_N,
qe;[-;t-,cC,}. Moreover,
wewillconsiderboth setsS,
andC,
tobe ordered in ascending order. Notice that to simplify ournotation we have included 1 in
S
and weplace it inposition 0. Weremark thatVn
S,
themultipleson ninS,
are obtained as nsiwhereEXAMPLE
1.Let’s
considerfor instance the third extension.In
this case wa 2.3.5 30, ma(30)
8,Ca {I,
7, Ii, 13,17, 19,23,29}
andSa {I, 7,
Ii,...,29, 31,37,..., 59,...,
30q+q,...,
N}.
Themultiples of any elementofSa,
say 7,are{7,
49, 77,--., 203,217,...}
whithcorrespondingordinal positions
{i,
13,20, 24, 31, 35, 42, 54,57,69,-..}.
In any extension of the Sieve, we need to know for any given element ne
Sk
its position,the position ofitssquare and ofsubsequentmultiples ofninSk.
Westartby definingafunctionthatmapseach element of
Sk
to its ordinalpositioninSk.LEMMA
2. LetCk
{cc0<c<c<"’<Cmk.1 }.
The position of any element of S,is given bytheinjectionPos:Sk-* +
definedbyPos(n)
mq+i, forn q’k+ci.(2.1)
EXTENSION OF THE SIEVE ERATOSTHENES
PROOF. If ixeCk, then n c for some i, and Pos
(n)
i. Otherwise, we can write Pos(n)
kk mk+i. HencePosisawell defined function.To see that Pos is one-to-one, let
nr
(lrZr +c andn
qtrk+ct. Assume thatPos(n) Pos(nt).
If q,<qt then mkqr+r mkqt+t ixnplies that m <mk(qt--q, r-t<m since 0 <r,t<xnk. This contradiction shows that q>_qt. Syxnmetrically, q >qt yields asimilar contradiction, hence% qt. It follows thatc c and thereforen nt.LEMMA 3. Letn,
Sk
wheren qnrk+c and qtk+Ct.ThenPos(nt) mk(q.t+c.qt)+Pos(c,,ct) (2.2)
PROOF.eos(nt) Pos((qn’k+Cn)t mkqnt+Pos(Cn(qdrk+ct)
mk(qnt
+cnqt)+Pos(cnct).
The congruence relation modulo rk partitions
Sk
into mk equivalent classes, where the elementsofCk
arethe canonical representatives, that is,Sk [.3 [cl,
where[c] {x Sk Ix c(mod rk)}- cCk
We willseethat for any n
[c]
the positions of themultiplesofn inSk
can be obtainedby adding cyclically the elements ofapredeterminedfiniteset ofdifferences, which in turndepend upon c. First,to determine thepositions of the multiples ofanyelement cCk
inSk,
weneedhefollowing.
DEFINITION4. Letc ndci+ beconsecutiveelements of
Ck.
Then forechnSk
weletPos(nci+l)-Pos(nci),
15 <mkd define
D {dn,i
15i
mk}.d,,i Pos(n(Zk+l))_Pos(nCmk)
mkThat is,
D
isthesetof differences of positions of thesuccessive mk+
1 multiples ofninSk
3. MAIN RESULTS
LEMMA
5. Let c6Ck.
The setD
contains M1 possible differences of positions between consecutivemultiplesofcinSk,d repeats cyclically.PROOF. Let n d nj be consecutive elements of
Sk
such that n k+C d ni qrk+q. Theneither(a)
qiandq
ci+,
or(b)
qj +1,cCmk
andq=l.
In
thefirstcase,itfollows from(2.1)
thatPos(cnj)-Pos(cn)
mkc(qj-qj) +Pos( ccj)-Pos(cq) Pos(ccj)-Pos(cci) de,
i.If
(b)
holds,thenwecanwriten (ch+l)rk+l. Hence,
Pos(cnj)-Pos(cni) [mkc + Pos(c(’k+l))]-
[mkcqi+ Pos(Ccmk)l de,ink.
542 A. R. QUESADA
Ineithercase
Pos(cnj)-Pos(cni)
Since, by construction, consecutive elements of
Sk
are congruentwith consecutive elements ofCk
modulo rk, and wehaveseen thatPos(cnj)-Pos(cni)
d....
itfollows thatD,
contains all the differences of positions between successive multiples of c inS,
and that they repeat cyclically.Next weextend the previous result toanyelementnin
S.
DEFINITION 6. Let
Ct+I--C,, <nlk
d, (Trk+l)-cmk,
mk and defineD{d,
<i< mk},that is,
Dk
is thesetofsuccessive differencesof thefirstmk+l
elements ofSk.
THEOREM 7. Letn=qTrk+c beanelement of
Sk.
Then, the following statements hold.(i)
Thesetof differences ofpositions ofconsecutivemultiples ofninSk
can be obtainedasD D[, +
mkqDk(3.1)
wherethesumis taken,asin thesumofmk-tuples,overthe i-th elements of thesets, < <mk.
(ii)
The position of thefirst multiple ofnto besieved, i.e.,n2,
isgiven byPos(n 2) mkq(n+c)+Pos(c2). (3.2)
(iii)
The multiples ofn thatfollow n in Skareobtained by cyclically adding the elements ofD,
startingwithdnx
forc %PROOF.
(i)
Letn qik+C andnj qj%+cjbeconsecutiveelements ofSk.
ThenPos(nnj) Pos(nni) q(nj
ni)mk+ Pos(cnj) Pos(cni). (3.3)
From Lemma 5we know thatPos(cnj)-Pos(cni)= de,i,
moreover, sincen[Ci]
andnje[cj]
areconsecutives,then itfollows fromDefinition6thatnj-n di,hence
(3.3)
yieldsPos(nnj)-Pos(nni) qdimk+d,i. (3.4)
Onthe otherhand,
d,i= Pos(ncj)-Pos(nci) q(c-ci)mk+POs(cci)-Pos(cci) qdimk+d,i
and theconclusionfollows from(3.4)
and(3.5).
(ii)
This is adear consequenceofLemma2.(iii)
Letn
andn
be consecutiveelementsinSk.
Lettingn n in(3.5),
we canwritePos(ninj) Pos(nini) qdimk+dci, dni,i,
thusPos(ninj) Pos(n) + dr,
i,i.Weremark that thislast theorem establishes thatonce thesets
D
kandD,
arecalculated, then foranyn6[c]
the set ofdiferencesD,
andPos(n 2)
arereadily known. Then, the multiples of n from n on inSk
are found by cyclically adding the elements ofD
starting atd,,i
forc
cj.
Is now clear, that sieving multiples of elements that belong to different equivalentTHE ERATOSTIIENES 543
clas.scs are independent processes, and therefore the algorittun is particularly well suited for parallel processing.
COROLLARY 8. Let t.n
Sk
be suchthat n(rood
rk). ThenD, D[ + mk(qt-qn)D ,
where thesmiis takenow,rthe i-th elements of thesets, _<i <mk.
PROOF. Since t--n (rood
rk),
thenD[,t D[,-.
Hence from the previous theorem, we obtainD, D[ (D,’ + mkqtD/)-(D +
mkqnDtmk(qt-qn)D. (3.6)
It is well known(see [5])
that the arithmetic complexity of the Sieve of Eratosthenes isO(n
logn).
Even though this remains unchanged in the k-th extension, the reduction in calculations issubstantial, asthenextLemmashows.LEMMA
9. The k-thextension of tile SieveofEratosthenes produces a-pTz0 reduction100 on thesizeofSu_,
andark-::rk)%
sizereductiononS.Proof. We know that
(r)=(pk-1)(rk.). Moreover,
inSk
each basic interval[qrk+l,
(q+l)rk]contains
(rk)elements,
whileSk.1
hasp(rk_)elements
in thesameinterval, hence]Sk-l]-lSk] Pk(k-l)--(’k)
1(3.7)
ISk.l[
pkq(Trk.l) -.
I00-, That is, the reduction in size ofSkwithrespect to
Sk_
is---z0.
From
(3.6)
we get[Ski --kllSk.,[,
from this we readily see thatISKI "trk)’slrK
and theconclusionfollows.
Table 1 below gives an idea of the size reduction of
Sk
with respect to S andSk.
respectively. Noticethatthe reductiononthe sizeof
Sk
is accompaniedwith anincreaseonthe corresponding sizeof(Trk),
andthereforeon the number of the sets ofdifferences as wellas on the sizeofthissets.At
thesametime,once wepass the fourth extension, the reductiononthe size ofSk
seemsto be rathersmallwhile(rk)
becomes toolarge. This suggeststhat evenforrelativelargevalues of
N,
the thirdorthefourthextension mayyield the faster results.k pk r
(rk)
10_._0Pk%
1(rk)
rk%
1 2 2 1
50% 50%
2 3 6 2
33% 67%
3 5 30 8
20% 73%
4 7 210 48
14% 77%
5 Ii 2310 480
9% 79%
6 13 30030 5760
8% 81%
TABLE
1REFERENCES
1.
BENELLOUN, S.A., An
incremental primalsieve,Acta
Informatica23,(1986),
119-125.544 2.
A. R. QUESADA
MAIRSON, H.G., Somenew upperbounds onthe generation ofprime numbers, Commun.
ACM
20
9(Sept.1977),
664-669.3. PRITCHARD, P., A sublinear additive sievefor finding prime numbers, Comlnun. ACM 24.1_ (Jan. 1981), 18-23.
4. D’OOGE, M. L.
(translator),
Nichomachus of Gerasa: Introduction to Arithmetic, Macmillan,New York, 1926.5.
KNUTH, D.,
The ArtofComputer Progranming, Vol. 2, 2nd ed., p. 394, AddisonWesley PublishingCompany,
Reading,Massachusetts, 1981.6. XUEDONG
LUO,
A practicalsieve algorithm forfindingprime numbers,Commun.
ACM3_
(Mar. 1989),
344-346.7.
QUESADA
A.R.,
Third Extension of Erathostenes’ Sieve. Commun. ACM 3_(Mar.
1992),
pp. 11-13.Mathematical Problems in Engineering
Special Issue on
Modeling Experimental Nonlinear Dynamics and Chaotic Scenarios
Call for Papers
Thinking about nonlinearity in engineering areas, up to the 70s, was focused on intentionally built nonlinear parts in order to improve the operational characteristics of a device or system. Keying, saturation, hysteretic phenomena, and dead zones were added to existing devices increasing their behavior diversity and precision. In this context, an intrinsic nonlinearity was treated just as a linear approximation, around equilibrium points.
Inspired on the rediscovering of the richness of nonlinear and chaotic phenomena, engineers started using analytical tools from “Qualitative Theory of Differential Equations,”
allowing more precise analysis and synthesis, in order to produce new vital products and services. Bifurcation theory, dynamical systems and chaos started to be part of the mandatory set of tools for design engineers.
This proposed special edition of the Mathematical Prob- lems in Engineering aims to provide a picture of the impor- tance of the bifurcation theory, relating it with nonlinear and chaotic dynamics for natural and engineered systems.
Ideas of how this dynamics can be captured through precisely tailored real and numerical experiments and understanding by the combination of specific tools that associate dynamical system theory and geometric tools in a very clever, sophis- ticated, and at the same time simple and unique analytical environment are the subject of this issue, allowing new methods to design high-precision devices and equipment.
Authors should follow the Mathematical Problems in Engineering manuscript format described at http://www .hindawi.com/journals/mpe/. Prospective authors should submit an electronic copy of their complete manuscript through the journal Manuscript Tracking System athttp://
mts.hindawi.com/according to the following timetable:
Manuscript Due February 1, 2009 First Round of Reviews May 1, 2009 Publication Date August 1, 2009
Guest Editors
José Roberto Castilho Piqueira,Telecommunication and Control Engineering Department, Polytechnic School, The University of São Paulo, 05508-970 São Paulo, Brazil;
Elbert E. Neher Macau,Laboratório Associado de Matemática Aplicada e Computação (LAC), Instituto Nacional de Pesquisas Espaciais (INPE), São Josè dos Campos, 12227-010 São Paulo, Brazil ; [email protected] Celso Grebogi,Department of Physics, King’s College, University of Aberdeen, Aberdeen AB24 3UE, UK;
Hindawi Publishing Corporation http://www.hindawi.com