Cod sursa(job #95500)

Utilizator 7RaduRadu Antohi 7Radu Data 29 octombrie 2007 09:55:37
Problema Factorial Scor 15
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.54 kb
program Fact;
label
   001;
var
   Fl : text;
   p: longint;
   n,i, j, k : longint;
begin
   Assign(Fl,'fact.in');
   Reset(Fl);
   ReadLn(Fl,p);
   Close(Fl);

   n := 1;
   while k <> p do
      begin
         j := 5;
         k := 0;
         while j <= n do
             begin
                k := k + n div j;
                j := j * 5;
              end;
         if k = p then
            goto 001;
         n :=  n + 1;
      end;

001: ;
  Assign(Fl,'fact.out');
  ReWrite(Fl);
  WriteLn(Fl,n);
  Close(Fl);
end.