Cod sursa(job #1414410)

Utilizator ButnaruButnaru George Butnaru Data 2 aprilie 2015 16:32:09
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.49 kb
program ciur;
type tabel=array[0..2000001] of byte;
var t:tabel;
    n,i,j,sol:longint;
    f1,f2:text;
function ciur(n:longint):longint;
begin
i:=2;
while (i*i<=n) do begin
if t[i]=0 then begin
j:=i*i;
while (j<=n) do begin
if t[j]=0 then sol:=sol-1; t[j]:=t[j]+1;
j:=j+i;
end; end;
i:=i+1;
end;
ciur:=sol;
end;
begin
assign (f1,'ciur.in');
assign (f2,'ciur.out');
reset (f1);
rewrite (f2);
readln (f1,n); sol:=n-1;
writeln (f2,ciur(n));
close (f1);
close (f2);
end.