Cod sursa(job #49176)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 5 aprilie 2007 15:13:37
Problema Indep Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.06 kb
type nmari=array[0..255] of byte;
var f,g:text;
x:array[1..512] of longint;
a:array[0..1,1..1000] of nmari;
n,i,j,k,l,m,l1,l2:longint;

function cmmdc(x,y:longint):longint;
begin
if x mod y=0 then cmmdc:=y
			 else cmmdc:=cmmdc(y, x mod y)
end;

procedure incr(var x,y:nmari);
begin
if y[0]>x[0] then x[0]:=y[0];
for i:=1 to x[0] do
	begin
    inc(x[i], y[i]);
    if (x[i]>=10) then
    			  begin
                  dec(x[i], 10);
                  inc(x[i+1]);
                  end;
    end;
if (x[x[0]+1]>0) then inc(x[0]);
end;



begin
assign(f,'indep.in');
assign(g,'indep.out');
reset(f);
rewrite(G);
readln(f,n);
for i:=1 to n do
begin
read(f,x[i]);
end;
l1:=0;
l2:=1;
a[0,x[1]][1]:=1;
a[0,x[1]][0]:=1;
for i:=2 to n do
begin
fillchar(a[l2],sizeof(a[l2]),0);
a[l2,x[i]][1]:=1;
a[l2,x[i]][0]:=1;
	for j:=1 to 1000 do
      begin
      incr(a[l2,j],a[l1,j]);
      incr(a[l2,cmmdc(j,x[i])],a[l1,j]);
      end;
m:=l1;
l1:=l2;
l2:=m;
end;
for i:=a[l1,1][0] downto 1 do write(g,a[l1,1][i]);
close(F);
close(G);
end.