Cod sursa(job #1192466)

Utilizator ROMaANUMitea Lucian ROMaANU Data 29 mai 2014 00:06:20
Problema Ciurul lui Eratosthenes Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 0.65 kb
type stiva=array[2..2000000] of longint;
var st:stiva;f,g:text;i,x,n,nr,t:longint;
function prim(i:longint):boolean;
var nr,j:byte;
begin
nr:=0;
for j:=2 to trunc(sqrt(i)) do
  if i mod j =0 then inc(nr);
if nr<>0 then prim:=false
         else prim:=true;
end;
begin
assign(f,'ciur.in');
reset(f);
read(f,n);
close(f);nr:=0;
for i:=2 to 10 do
   if prim(i) then
           begin
           t:=1;inc(nr);
           repeat
           inc(t);
           if i*t<=n then st[i*t]:=1;
           until i*t>=n;
           end;
for i:=11 to n do
  if st[i]<>1 then inc(nr);
assign(g,'ciur.out');
rewrite(g);
write(g,nr);
close(g);
end.