function SieveE ##//////////////////////////////////////////////////////// ## Name: Peter M. Maurer ## Program: Sieve of Eratosthenes ## Due: Never ## Language: Euler ##/////////////////////////////////////////////////////// ## define the sieve data structure Candidates = 1:1000; for i=1 to 1000 ## everything is potentially prime until proven otherwise Candidates[i] = 1; end ## 1 is not prime, so flag it off Candidates[1] = 0; ## start the sieve with the integer 1 i = 1; repeat if i>=1000 break endif ## advance to the next un-crossed out number. ## this number must be a prime repeat if i>=1000 break endif if Candidates[i] != 0 break endif i = i + 1; end ## insure against running off the end of the data structure if i<1000 ## cross out all multiples of the prime, starting with 2*p. j = 2; k = i * j; repeat if k >= 1000 break endif Candidates[k] = 0; j = j + 1; k = i * j; end i = i + 1; endif end ## all uncrossed-out numbers are prime (and only those numbers) ## print all primes "Prime List" for i=1 to 999 if Candidates[i] != 0 i endif end return -1 endfunction