Pagini recente » Cod sursa (job #39778) | Cod sursa (job #2114434) | Cod sursa (job #3230506) | Cod sursa (job #24996) | Cod sursa (job #255691)
Cod sursa(job #255691)
program fractii;
var f,g:text;
p,pp:array[1..1000000]of longint;
n,x,ci,ok,y,cj,c,s,max,i,j:longint;
begin
assign(f,'fractii.in');
assign(g,'fractii.out');
reset(f);
rewrite(g);
read(f,n);
y:=0;
for i:=2 to n do
begin
x:=2;
while(i*x<=n)do
begin
if(p[x]=0)and(x>max)and ((trunc(sqrt(x)))*(trunc(sqrt(x)))<>x) then begin y:=y+1;
pp[y]:=x;
max:=x;
end;
p[i*x]:=1;
x:=x+1;
end;
end;
s:=s+(n-1)*2+1;
for i:=2 to n do begin
if(p[i]=0)then
begin
c:=i-2;
s:=s+c*2;
for j:=i to n do
if(j mod i<>0)and(p[j]<>0)then s:=s+2;
end;
if(p[i]<>0) then
{for j:=i to n do
if(p[j]<>0)then begin
ci:=i;
cj:=j;
while(ci<>cj)do
if(ci>cj)then ci:=ci-cj
else cj:=cj-ci;
if(ci=1)then s:=s+2;
end; }
for j:=i to n do
if(p[j]<>0)then begin
ci:=i;
cj:=j;
ok:=0;
for c:=1 to y do
if(ci mod pp[c]=0)and(cj mod pp[c]=0)then begin ok:=1;
break;
end;
if(ok=0)then s:=s+2;
end;
end;
write(g,s);
close(f);
close(g);
end.