Cod sursa(job #125937)

Utilizator TudorutzuMusoiu Tudor Tudorutzu Data 20 ianuarie 2008 21:41:54
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.59 kb
var f,g:text;
    ok:boolean;
    a,b,c,x,y,p:longint;
begin
     assign(f,'factorial.in'); reset(f);
     assign(g,'factorial.out'); rewrite(g);
     readln(f,p);
     a:=0;        ok:=false;
     b:=maxlongint;
     if p=0 then c:=-1
            else
     while not ok do
     begin
          y:=5;
          c:=(a+b)div 2;
          while c div y = 0 do
          begin
               x:=x+c div y;
               y:=y*5;
          end;
          if x<p then b:=c
                 else a:=c;
          if x=p then ok:=true;
     end;
     writeln(g,c);
     close(g);
end.