Cod sursa(job #109274)

Utilizator runnaway90Oprescu Radu Constantin runnaway90 Data 25 noiembrie 2007 09:51:09
Problema Economie Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 1, Clasa a 9-a Marime 2.25 kb
var f:text;
        n,i,j,cont,cont2,max,q,nr:longint;
        a:array[0..1000] of word;
        p:array[0..55000]of shortint;
        c:array[0..20000,0..2]of word;
        ok:boolean;
begin
        assign(f,'economie.in');
        reset(f);
                readln(f,n);
                ok:=false;
                for i:=1 to n do
                begin
                        read(f,a[i]);
                        if a[i]>max then
                                max:=a[i];
                        if a[i]=1 then
                                ok:=true;
                end;
        close(f);
        assign(f,'economie.out');
        rewrite(f);
        if ok then
        begin
                writeln(f,1);
                write(f,1);
        end
        else
        begin
              nr:=1;
              c[1,1]:=2;
              i:=3;
              while i<max do
              begin
                if p[i]=0 then
                begin
                        inc(nr);
                        c[nr,1]:=i;
                        j:=3*i;
                        while j<=max do
                        begin
                                p[j]:=1;
                                j:=j+i;
                        end;
                end;
              i:=i+2;
              end;
              cont:=0;
              for i:=1 to n do
              begin
                nr:=0;
                while a[i]<>1 do
                begin
                        inc(nr);
                        if a[i] mod c[nr,1]=0 then
                        begin
                                if c[nr,2]=0 then
                                        inc(cont);
                                c[nr,2]:=1;
                        end;
                        while a[i] mod c[nr,1]=0 do
                                a[i]:=a[i] div c[nr,1];
                end;
              end;
              cont2:=0;
              writeln(f,cont);
              for i:=1 to nr do
              if c[i,2]=1 then
              begin
                inc(cont2);
                if cont2=cont then
                write(f,c[i,1])
                else
                writeln(f,c[i,1]);
              end;
        end;

        close(f);
end.