Cod sursa(job #1004897)
Utilizator | andrei sulzandrei | Data | 3 octombrie 2013 19:46:24 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
program ciurulluierathostenes;
var v:array[2..2000000] of boolean;
nr,k,i,j,n:longint;
f:text;
begin
assign(f,'ciur.in'); reset(f);
readln(f,n);
close(f);
assign(f,'ciur.out'); rewrite(f);
k:=3;
while k<=n do begin
v[k]:=true;
inc(k,2);
end;
nr:=1;
i:=3;
while (i<=trunc(sqrt(n))) do begin
j:=sqr(i);
while j<=n do begin
v[j]:=false;
inc(j,i);
end;
inc(i,2);
end;
for i:=3 to n do
if v[i] then inc(nr);
writeln(f,nr);
close(f);
end.