Cod sursa(job #139289)

Utilizator radupoenaruPoenaru Radu Constantin radupoenaru Data 19 februarie 2008 22:07:52
Problema Factoriale Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.34 kb
var n,k,max,i,j,a,d,r,x,xx,z,aux,maxx:longint;
    v:array[1..1000] of byte;
    p:array[1..20] of byte;
    f,g:text;
begin
assign(f,'factoriale.in');reset(f);
assign(g,'factoriale.out');rewrite(g);
read(f,n,k);
max:=0;
for i:=1 to n do begin
                 read(f,x);
                 for j:=2 to x do begin
                                  d:=3;
                                  a:=j;
                                  while a mod 2=0 do begin
                                                     inc(v[2]);
                                                     a:=a div 2;
                                                     end;
                                  repeat
                                       while a mod d=0 do begin
                                                          inc(v[d]);
                                                          a:=a div d;
                                                          end;
                                       d:=d+2;
                                  until a=1;
                                  end;
                 if max<x then max:=x;
                 end;
for i:=2 to 20 do p[i]:=0;
p[1]:=1;
for i:=2 to max do begin
                   r:=v[i] mod k;
                   if r<>0 then for j:=1 to (k-r) do
                                                     if i<=9 then for xx:=1 to 20 do begin
                                                                                     p[xx]:=p[xx]*i;
                                                                                     if p[xx]>9 then begin
                                                                                                aux:=p[xx];
                                                                                                p[xx]:=p[xx] mod 10;
                                                                                                p[xx+1]:=p[xx+1]+(aux div 10);
                                                                                                     end;
                                                                                     end
                                                              else begin
                                                              z:=i;
                                                              while z<>0 do begin
                                                                            p[xx]:=p[xx]*(z mod 10);
                                                                            if p[xx]>9 then begin
                                                                                             aux:=p[xx];
                                                                                             p[xx]:=p[xx] mod 10;
                                                                                             p[xx+1]:=p[xx+1]+(aux div 10);
                                                                                            end;
                                                                            end;
                                                                    end;
                      end;
i:=20;
while p[i]=0 do begin
                inc(maxx);
                i:=i-1;
                end;
for i:=(20-maxx) downto 1 do write(g,p[i]);
close(f);
close(g);
end.