begin {initialize} Sieve := [2 .. N]; Primes:= []; NextPrime·= 2; repeat {find next prime } while not (NextPrime in Sieve) do NextPrime := Succ(NextPrime); Primes := Primes + [NextPrime]; NewPrime := 2 * NextPrime - 1; Multiple := NextPrime; while Multiple <= N do eliminate begin Sieve:= Sieve - [Multiple]; Multiple := Multiple + NewPrime; end until Sieve = [] end . 

A design goal for Pascal implementations is that all basic set operations execute relatively fast. Some implementations restrict the maximum size of sets according to their "wordlength," so that each element of the base set is represented by one bit (0 meaning absence, 1 meaning presence). Most implementations would not accept a set with 10,000 elements. These considerations lead to an adjustment in the data representation, as shown in Program 8.5. 

A large set can be represented as an array of smaller sets such that each "fits" into a few words (implementation dependent). The following program uses the second sketch as an abstract model of the algorithm. Sieve and Primes are redefined as arrays of sets; Next is defined as a record. 

program Prime3(Output); { Program 8.5 - Generate the primes between 3 .. 10000 using a sieve containing odd integers in this range. const SetSize = 128 { implementation-dependent; >= 2 }; MaxElement = 127 { SetSize - 1 }; SetParts = 39 { = 10000 div Setsize div 2 }; type Natural o .. Maxlnt; 

