Pagini recente » Cod sursa (job #1574607) | Cod sursa (job #1749946) | Cod sursa (job #2754743) | Cod sursa (job #2150433) | Cod sursa (job #114743)
Cod sursa(job #114743)
var fi,fo:text;
i,n,x,max,ct,j:longint;
rez,nr_div:int64;
nr:array[1..1000100]of byte;
m:array[1..1000100]of longint;
function prim(nr:longint):boolean;
var i:longint;
begin
i:=2; nr_div:=0; prim:=true;
while i<=nr do
if nr mod i=0 then
begin
ct:=0;
while nr mod i=0 do
begin
nr:=nr div i;
inc(ct);
if ct>1 then begin prim:=false; exit; end;
end;
inc(nr_div);
inc(i);
end
else inc(i);
if nr_div>1 then prim:=false;
end;
procedure verif(i:longint);
var ok:boolean;
begin
ok:=prim(i);
if ok=true then rez:=rez+(m[i]*(m[i]-1) shr 1)
else
if nr_div>1 then
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);
max:=-maxint;
rez:=0;
for i:=1 to n do
begin
readln(fi,x);
nr[x]:=1;
if x>max then max:=x; end;
for i:=2 to max do
begin
for j:=1 to max div i do
if(i and 1 <>0)and(j and 1 <>0) then
if nr[i*j]=1 then inc(m[i]);
if (m[i]>0) then verif(i);
end;
rez:=n*(n-1) shr 1 - rez;
writeln(fo,rez);
close(fi);
close(fo);
end.