Cod sursa(job #153332)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 10 martie 2008 14:10:29
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.57 kb
var v:array[0..2100000]of boolean;
    p:array[1..20000]of longint;
    n,j,k,u,i:longint;
    f:text;
begin
   assign(f,'ciur.in');
   reset(f);
   read(f,n);
   close(f);
   for i:=1 to n do
   v[i]:=true;
   i:=1;
   for i:=2 to n do
   if v[i] then begin j:=i;
                      k:=k+1;
                      while(j+i<=n)and(j+i>0)do
                      begin
                      j:=j+i;
                      v[j]:=false;
                      end;
                end;
   assign(f,'ciur.out');
   rewrite(f);
   writeln(f,k);
   close(f);
end.