Cod sursa(job #22105)

Utilizator TudorutzuMusoiu Tudor Tudorutzu Data 25 februarie 2007 17:26:54
Problema Factorial Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.5 kb
var f,g:text;
    p,x,nr,y,z,i,m:longint;
begin
     assign(f,'fact.in'); reset(f);
     assign(g,'fact.out'); rewrite(g);
     read(f,p);  x:=0;
     if p<0 then x:=0;
     if p=0 then x:=1;
     if p>0 then
     begin
     m:=0; y:=1;
     repeat
     begin
          y:=y*5;
          inc(m);
     end
     until y>p*5; dec(m); z:=0;
     for i:=1 to m do z:=z+i-1;
     p:=p-z;
     x:=5*p;
     end;
     if x=0 then write(g,'-1')
            else write(g,x);
     close(g);
end.