Pagini recente » Cod sursa (job #691242) | Cod sursa (job #1177752) | Cod sursa (job #15049) | Istoria paginii runda/oji_2005_10/clasament | Cod sursa (job #166426)
Cod sursa(job #166426)
type vector=array[1..1000000] of shortint;
var n,i,s:int64;
f,g:text;
a,b:vector;
{---Functia putere---}
function putere(n,p:int64):int64;
begin
if p=0 then putere:=1
else if odd(p) then putere:=n*putere(sqr(n),(p-1) div 2)
else putere:=putere(sqr(n),p div 2);
end;
{---Sfarsit functie putere---}
{---Ciurul lui Eratostene---}
procedure ciur(n:int64;var a:vector);
var i,j:int64;
begin
a[1]:=1;
i:=2;
while i<=trunc(sqrt(n)) do
begin
j:=sqr(i);
while j<=n do
begin
a[j]:=j;
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:int64):int64;
var p:real;
i:int64;
begin
{ciur(n,a);}
if n=0 then t:=1
else if a[n]=0 then t:=n-1
else
begin
p:=n;
i:=1;
while i<=n do
begin
if (a[i]=0) and (n mod i=0) then p:=p*(1-1/i);
i:=i+1;
end;
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; i:=2;
while i<=n do
begin
s:=s+2*t(i);
i:=i+1;
end;
writeln(g,s);
close(f); close(g);
end.