SIEVE| begin comment library A0, A1, A5, A15; integer p, m, n, r; n := 10 000; writetext(30, [[c_]number * of * primes * below:]); write(30, format([nddddd_]), n); writetext(30, [:]); r := entier(2×sqrt(n)); begin boolean array candidate [2 : n]; comment deal with 2 separately; candidate[2] := true ; for m := 4 step 2 until n do candidate[m] := false; comment now deal with the other factors; for p := 3 step 2 until n do candidate[p]:= true ; for p := 3 step 2 until r do begin if candidate[p] then for m := p × p step p until n do candidate[m] := false end; m := 1; comment because 2 is prime; for p := 3 step 2 until n do if candidate[p] then m := m + 1; end; write(30, format([ndddddc_]), m); close(30); end |