Cod sursa(job #317834)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 25 mai 2009 12:47:49
Problema Factorial Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.22 kb
program Fact;
const a : array [1..13] of longint = (5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125);
      b:array [1..13] of longint =  (1,6,31,156,781,3906,19531,97656,488281,2441406,12207031,61035156,305175781);
var fin,fout:text;
    i,j,aux,n,m,p,zero,nr,rez:longint;
begin
     assign(fin,'fact.in'); reset(fin); assign(fout,'fact.out'); rewrite(fout);


     readln(fin,p); zero:=0;

     if p = 0 then
     begin
         writeln(fout,1);
         Close(fout);
         Halt;
     end;

{     nr:=0;
     while zero <> p do
     begin
          nr:=nr+5;
          aux:=nr;
          while aux mod 5 = 0 do
          begin
              inc(zero);
              aux:=aux div 5;
          end;
     end;

     if zero = p then writeln(fout,nr)
     Else writeln(fout,-1);}
     while p > 0 do
     begin
         i:=13;
         while p < b[i] do
         begin
             dec(i);
         end;

         p:=p-b[i];
         rez:=rez+a[i];
         {if p = 10 then
         begin
           writeln(fout,1);
         end;              }
     end;


     if p <0 then writeln(fout,-1  )
     Else
     writeln(fout,rez);

     close(fin); Close(fout);
end.