Cod sursa(job #1158939)
| Utilizator | Data | 29 martie 2014 10:55:42 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
var
i, m, p, n, np : longint;
a : array [1..2000000] of byte;
fi, fo : text;
begin
assign (fi, 'ciur.in'); reset (fi);
assign (fo, 'ciur.out'); rewrite (fo);
read (fi, n);
for i := 1 to n do
a[i] := 1;
for p := 2 to n do
if a[p] = 1 then { Numarul nu este eliminat din sir. }
begin
m := 2*p;
while m <= n do
begin
a[m] := 0; { Eliminam multiplul din sir. }
m := m+p; { Trecem la multiplul urmator. }
end;
end;
for i := 2 to n do
if a[i] = 1 then
inc(np);
write (fo, np);
close (fo);
end.