Cod sursa(job #137441)

Utilizator DiaconuDiaconu Loredana Diaconu Data 17 februarie 2008 12:12:26
Problema Factoriale Scor 10
Compilator fpc Status done
Runda preONI 2008, Runda 4, Clasele 5-8 Marime 0.66 kb
var    f,g:text;
       s:int64;
       n,k,i,j,y,cj,nr:integer;
       x,exp:array[1..100] of integer;
begin
assign (f,'factoriale.in');reset (f);
assign (g,'factoriale.out');rewrite (g);
readln (f,n,k);
for i:=1 to n do
 read (f,x[i]);
for i:=1 to n do begin
 for j:=2 to x[i] do begin
  nr:=1;
  cj:=j;
  while cj<>1 do begin
   inc(nr);
   if (cj mod nr)=0 then begin
    while (cj mod nr)=0 do begin
     cj:=cj div nr;
     inc(exp[nr]);
    end;
   end;
  end;
 end;
end;
s:=1;
for i:=1 to 100 do
 if exp[i]<>0 then begin
  y:=exp[i] mod k;
  for j:=1 to y do
   s:=s*i;
 end;
writeln (g,s);
close(f);close(g);
end.