Pagini recente » Cod sursa (job #2642383) | Cod sursa (job #1598345) | Cod sursa (job #3004374) | Cod sursa (job #1634454) | Cod sursa (job #42877)
Cod sursa(job #42877)
program fractii;
var v:array[0..10000] of byte;
b:array[0..10000] of longint;
i,j,s,n,m,nr,x,y,p:longint;
ok:boolean;
a:array[0..1000000] of longint;
f,g:text;
procedure ciur;
var i,j:longint;
begin
i:=1;
while ((i*i) shl 1)+(i shl 1) <=n do begin
if ((v[i shr 3] shr (i and 7)) and 1 )=0 then begin
j:=((i*i) shl 1)+ (i shl 1);
while 2*j+1<=n 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;
b[0]:=1; b[1]:=2;
for i:=1 to n do
if ((v[i shr 3] shr (i and 7)) and 1)=0 then
if (2*i+1<=n) then begin
inc(b[0]); b[b[0]]:=2*i+1;
end;
end;
begin
assign(f,'fractii.in'); reset(f);
assign(g,'fractii.out'); rewrite(g);
readln(f,m); n:=trunc(sqrt(m))+1;
a[1]:=1;
ciur; s:=1;
for i:=2 to m do begin
j:=1; ok:=false; x:=i;
while (ok=false)and(trunc(sqrt(i))>=b[j]) do begin
p:=1; nr:=0;
while (x mod b[j]=0) and(b[j]<=trunc(sqrt(i))) do begin
p:=p*b[j]; inc(nr);
x:=x div b[j];
ok:=true;
end;
inc(j);
end;
{ phi[p^e] = (p-1) * p^(e-1); phi[2^4] = 1 * 2^3; }
{}
if x=i then a[i]:=x-1
else if (x=1)then a[i]:=(b[j-1]-1)*(p div b[j-1] )
else a[i]:=a[i div p]*a[p];
s:=s +2*a[i];
end;
writeln(g,s);
close(g); close(f);
end.