Pagini recente » Cod sursa (job #256975) | Cod sursa (job #1152676) | Cod sursa (job #234317) | Cod sursa (job #1926842) | Cod sursa (job #165837)
Cod sursa(job #165837)
type vector=array[1..1000000] of byte;
var n,i,s:longint;
f,g:text;
a:vector;
{---Functia putere---}
{---Sfarsit functie putere---}
{---Ciurul lui Eratostene---}
procedure ciur(n:longint;var a:vector);
var i,j:longint;
begin
a[1]:=1;
i:=2;
while i<=trunc(sqrt(n)) do
begin
j:=sqr(i);
while j<=n do
begin
a[j]:=j;{a[j]:=1}
j:=j+i;
end;
if i=2 then i:=3
else i:=i+2;
end;
end;
{---Sfarsit Ciurul lui Eratostene---}
{---Functia totient <=> Indicatorul lui Euler---}
function t(n:longint):longint;
var p:real;
i:longint;
begin
{ciur(n,a);}
if n=0 then t:=1
else begin
p:=n;
for i:=1 to n do
if (a[i]=0) and (n mod i=0) then p:=p*(1-1/i);
t:=trunc(p);
end;
end;
{---Sfarsit functie totient---}
begin
assign(f,'fractii.in'); reset(f);
assign(g,'fractii.out'); rewrite(g);
readln(f,n);
ciur(n,a);
s:=1;
for i:=2 to n do
begin
if a[i]=0 then s:=s+2*(i-1)
else s:=s+2*t(i);
end;
writeln(g,s);
close(f); close(g);
end.