$////////////////////////////////////////////////////////// $// Name: Peter M. Maurer $// Program: Sieve of Eratosthenes $// Due: Never $// Language: SETL $////////////////////////////////////////////////////////// program SieveE; $ define the sieve data structure candidates := [1,1]; i := 3; loop while i<1000 do $ everything is potentially prime until proven otherwise Candidates(i) := 1; i := i + 1; end loop; $ Neither 1 nor 0 is prime, so flag them off Candidates(1) := 0; $ start the sieve with the integer 1 i := 1; loop while i<1000 do $ advance to the next un-crossed out number. $ this number must be a prime loop while i<1000 and Candidates(i) = 0 do i := i + 1; end loop; $ insure against running off the end of the data structure if i<1000 then $ cross out all multiples of the prime, starting with 2*p. j := 2; loop while j*i < 1000 do Candidates(j*i) := 0; j := j + 1; end loop; $ advance to the next candidate i := i + 1; end if; end loop; $ all uncrossed-out numbers are prime (and only those numbers) $ print all primes i := 1; loop while i<1000 do if Candidates(i) /= 0 then print(i,' is prime'); end if; i := i + 1; end loop; end program;