Cod sursa(job #264888)

Utilizator butler1234Cioc Stefan butler1234 Data 22 februarie 2009 22:08:03
Problema Ciurul lui Eratosthenes Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 0.46 kb
program ciur;
var s,prim:array[1..10000] of integer;
    n,i,j,cnt,nr,x,k:word;
    f1,f2:text;

begin
assign(f1,'ciur.in'); reset(f1);
assign(f2,'ciur.out'); rewrite(f2);



readln(f1,n);
cnt:=0;
for i:=2 to n do
  prim[i]:=1;
for i:=2 to n do
   if (prim[i]=1)  then
     begin
     cnt:=cnt+1;
     j:=i+i;
     while j<=n do
     begin
       prim[j]:=0;
       j:=j+i;
       end;
     end;
writeln(f2,cnt);
close(f1);
close(f2);
end.