Pagini recente » Cod sursa (job #1819448) | Cod sursa (job #3253713) | Cod sursa (job #2348837) | Cod sursa (job #2711058) | Cod sursa (job #406214)
Cod sursa(job #406214)
//00:27 28.02.2010
//Moldovan Ilie Marcel
//Ciurul lui Eratosthenes
const maxn=2000000;
masca:array[0..7]of byte=(1,2,4,8,16,32,64,128);
type vector=array[1..maxn shr 4+1]of byte;
var n,nr,i,pv,pm:longint;
j:int64;
v:vector;//al k-lea bit din v[p] este 0 daca 16*(p-1)+2*k+1 este prim
begin
assign(input,'ciur.in');
reset(input);
assign(output,'ciur.out');
rewrite(output);
readln(n);
nr:=1;
i:=3;
while i<=n do
begin
if v[(i-2) shr 4+1] and masca[((i-2) mod 16)shr 1]=0 then
begin
inc(nr);
j:=int64(i)*i;
while j<=n do begin
pv:=(j-2) shr 4+1;
pm:=((j-2) mod 16)shr 1;
if v[pv] and masca[pm]=0 then v[pv]:=v[pv]+masca[pm];
j:=j+i shl 1;
end;
end;
i:=i+2;
end;
writeln(nr);
close(output);
close(input);
end.