Pagini recente » Cod sursa (job #169900) | Cod sursa (job #2926533) | Cod sursa (job #2694249) | Cod sursa (job #1560843) | Cod sursa (job #115680)
Cod sursa(job #115680)
var fi,fo:text;
n,x,nr_div,i,j,max:longint;
ct:byte;
rez:int64;
nr:array[1..1000010]of byte;
m:array[1..1000010]of longint;
procedure prim(nr:longint);
var i:longint;
begin
i:=2; nr_div:=1; ct:=1;
while i<=trunc(sqrt(nr)) do
begin
if nr mod i=0 then
begin
if nr mod (sqr(i))=0 then begin ct:=2; exit; end;
inc(nr_div);
nr:=nr div i;
end;
inc(i);
end;
end;
procedure verif(i:longint);
begin
prim(i);
if ct=1 then
if nr_div and 1 = 1 then rez:=rez + (m[i]*(m[i]-1)) shr 1
else rez:=rez - (m[i]*(m[i]-1)) shr 1;
end;
begin
assign(fi,'pairs.in'); reset(fi);
assign(fo,'pairs.out'); rewrite(fo);
readln(fi,n);
rez:=0; max:=-maxint;
m[1]:=0;
for i:=1 to n do
begin
readln(fi,x);
{if x and 1=0 then inc(m[2]);}
for j:=2 to trunc(sqrt(x)) do
if x mod j=0 then
begin
inc(m[j]); inc(m[x div j]); end;
inc(m[x]);
if max<x then max:=x;
end;
{if (m[2]>0) then verif(2);}
{for i:=3 to max do
begin
for j:=1 to max div i do
if nr[i*j]=1 then inc(m[i]);
if (m[i]>0) then verif(i);
end;}
for i:=2 to max do
if m[i]>0 then verif(i);
rez:=(n*(n-1) shr 1) - rez;
writeln(fo,rez);
close(fi); close(fo);
end.