Cod sursa(job #137423)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 17 februarie 2008 12:06:13
Problema Factoriale Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 4, Clasele 5-8 Marime 1.2 kb
program NOD_SoFTWARE;
var p,nr,q,i,j,n,m,k:longint;
    fost,suma,rez:longint;
    fin,fout:text;
    gasit:boolean;
{*------------------*}
procedure fact(i:integer);
begin
     fost:=1;
     for q:=1 to i do
     begin
{          suma:=1;}
          suma:=fost*q;
          fost:=suma;
     end;
end;
{*------------------*}
begin
     assign(fin,'factoriale.in'); reset(fin);
     assign(fout,'factoriale.out'); rewrite(fout);
     readln(fin,n,k);

     rez:=1;
     for i:=1 to n do
     begin
          read(fin,nr);
          fact(nr);
          rez:=rez*suma;
     end;

     gasit:=false;
     i:=0;
     p:=0;
     while not gasit do
     begin
          inc(i);
          suma:=rez*i;
          j:=1;
          while p <=suma do
          begin
               inc(j);
               p:=j;
               for Q:=2 to k do p:=p*j;
               if p = suma then
               begin
                    writeln(fout,suma);
                    writeln(fout,j);
                    writeln(fout,i);
                    close(fout);
                    exit;
               end;
          end;
     end;

     writeln(fout,rez);
     close(fin);
     close(fout);
end.