Vous êtes sur la page 1sur 1

procedure CribleEratosthene(var nombres: array of Byte);

var
i,j, step : integer;
begin
// La cellule prend la valeur 1 si son indice est premier, 0 sinon
Nombres[0] := 0; Nombres[1] := 0;
Nombres[2] := 1;
// Initialise le tableau en éliminant d'office les nombres pairs
for i := 3 to High(Nombres) do
Nombres[i] := (i and 1);
for i := 2 to High(Nombres) do
if Nombres[i]=1 then
begin
// on recherche
j := i*i;
step := i * 2;
while j <= High(Nombres)do
begin
Nombres[j] := 0;
inc(j, step);
end;
end;
End;

Vous aimerez peut-être aussi