var Sieve, Primes: array [O .. SetParts] set of O .. MaxEleme I ; NextPrime: record Part: 0 SetPart. ; Element: 0 .. MaxE ~ment end; Multiple, NewPrime: Na' 'Hal; P, N, Count: Natural; Empty: Boolean; begin {initialize} for P : = 0 to SetParts d, begin Sieve[P] := [0 .. MaxE "ment]; Primes[P] := [] end; Sieve[O] := Sieve[O] - [I I; Empty:= False; NextPrime.Part := 0; Ne:.1 "'rime.Element := 1; with NextPrime do repeat {find next pr.-e } while not (Element ir Sieve[Part]) do Element := Succ(Elt~ent); Primes [Part] := Prim~3lPart] + [Element]; NewPrime := 2 * ElemE·nt + 1; Multiple := Element; P:= Part; while P <= SetParts C:J {eliminate begin Sieve [P] .-;ieve [P] - [Multiple]; P := P + Part * ;; Multiple := Mult:,le + NewPrime; while Multiple > ~dxElement do end; begin P := P ~ _. Multiple . - ~ I.' iple - SetSize end if Sieve [Part] = [] t It'll begin Empty:= Trl, Element:= 0 end; while Empty and (Part <: SetParts) do begin Part := Part + 1; Empty:= Sieve[Part] [] end until Empty; 

