Cod sursa(job #587082)
| Utilizator | Data | 3 mai 2011 20:40:22 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
var a:array[1..10000001] of byte;
i,n,nr,r:longint;
j,k:int64;
begin
assign(input,'ciur.in');reset(input);
assign(output,'ciur.out');rewrite(output);
readln(n);
nr:=1;
i:=1;r:=n mod 2;
n:=n div 2-1+r;
for i:=1 to trunc(sqrt(n*2+r)) div 2 do
if a[i]=0 then
begin
k:=(i shl 1+1);
j:=k*k;
while j<=(n*2+1) do
begin
a[j shr 1]:=1;
j:=j+2*k;
end;
end;
for i:=1 to n do
if a[i]=0 then inc(nr);
write(nr);
end.
