with Text_io; use Text_io; procedure PRIMES is -- Eratosthene's sieve package IIO is new Text_IO.Integer_io(integer); --need integer output N:constant integer:=1500; --largest number to be considered SCREEN_WIDTH:constant integer:=60; LINES:constant integer:=N / screen_width - 1; type PRIME_CLASS is (UNKNOWN, PRIME, COMPOSITE); type PRIME_CLASSES is array(1..N) of PRIME_CLASS; STATE: PRIME_CLASSES:=(1..N=>UNKNOWN); -- State of numbers... MULTIPLE:integer; begin iio.Put(1); STATE(1):=PRIME; for P in 2..N loop -- For each possible prime in turn... if STATE(P)=UNKNOWN then -- it isn't a multiple of a smaller prime iio.put(P); STATE(P):=PRIME; MULTIPLE:=P+P; for MULTIPLIER in 2..N loop -- multiple = multiplier * P exit when MULTIPLE > N; STATE(MULTIPLE):=COMPOSITE; MULTIPLE:=MULTIPLE + P; end loop; end if; end loop; -- print out the sieve text_io.new_line; for line_nbr in 0..lines loop for col_nbr in 1 .. screen_width loop case STATE(line_nbr*screen_width+col_nbr) is when UNKNOWN => text_io.put("u"); when PRIME => text_io.put("P"); when COMPOSITE=> text_io.put("."); end case; end loop; text_io.new_line; end loop; end PRIMES;