Pagini recente » Cod sursa (job #2120765) | infoarena - comunitate informatica, concursuri de programare | Cod sursa (job #1825928) | Cod sursa (job #1162232) | Cod sursa (job #196997)
Cod sursa(job #196997)
var v:array[1..10000] of longint;
c:array[1..30000] of boolean;
n,i:longint;
k:integer;
kont:int64;
f:text;
procedure ciur(x:longint);
var i,j,t:longint;
begin
v[1]:=2;
k:=1;
i:=3;
t:=trunc(sqrt(x));
while i<=t do
begin
if c[i]=false then
begin
inc(k);
v[k]:=i;
j:=sqr(i);
while j<=x do begin c[j]:=true; inc(j,i); end;
end;
inc(i,2);
end;
if not odd(i) then inc(i);
while i<=x do
begin
if c[i]=false then begin inc(k); v[k]:=i; end;
inc(i,2);
end;
end;
function phi(x:longint):int64;
var p:currency; k:longint;
begin
p:=1;
k:=1;
while v[k]<(x shr 1)-1 do
begin
if x mod v[k]=0 then p:=p*(1-1/v[k]);
inc(k);
end;
if p=1 then phi:=x-1
else
begin
p:=p*x;
phi:=trunc(p);
end;
end;
begin
assign(f,'fractii.in');
reset(f);
read(f,n);
close(f);
ciur(30000);
assign(f,'fractii.out');
rewrite(f);
if n=1 then write(f,1)
else
begin
kont:=0;
for i:=2 to n do inc(kont,phi(i));
write(f,2*kont+1);
end;
// for i:=2 to n do writeln(f,i,' ',phi(i));
close(f);
end.