Cod sursa(job #50978)
Utilizator | Data | 9 aprilie 2007 14:55:32 | |
---|---|---|---|
Problema | Fractii | Scor | 20 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 2.14 kb |
type sir=array[1..1000000] of integer;
var n,nr,i,j,a,b,c,g,k,h,t:longint; f1,f2:text; v,z:sir; x:array[0..1000000] of longint;
procedure ciur(b:longint);
var i,j:longint;
begin
i:=1;
while ((i*i) shl 1)+(i shl 1)<=b do
begin
if v[i shr 3] and (1 shl (i and 7))=0 then
begin
j:=((i*i)shl 1)+(i shl 1);
while 2*j+1<=b do
begin
v[j shr 3]:=v[j shr 3]or(1 shl(j and 7));
j:=j+(i shl 1)+1;
end;
end;
inc(i);
end;
i:=0;
x[1]:=2;
x[0]:=1;
while 2*i+1<=n do
begin
inc(i);
if v[i shr 3] and (1 shl (i and 7))=0 then
begin
inc(x[0]);
x[x[0]]:=2*i+1;
end;
end;
end;
begin
assign(f1,'fractii.in');
reset(f1);
assign(f2,'fractii.out');
rewrite(f2);
read(f1,n);
nr:=n;
Ciur(n);
for g:=2 to n do
begin
k:=g;
t:=n;
h:=0;
for i:=1 to x[0] do
if k mod x[i]=0 then
begin
j:=x[i];
while j<=n do
begin
if z[j]=0 then
begin
z[j]:=1;
dec(t);
inc(h);
v[h]:=j;
end;
inc(j,x[i]);
end;
end;
for i:=1 to h do z[v[i]]:=0;
nr:=nr+t;
end;
writeln(f2,nr);
close(f1);
close(f2);
end.