Cod sursa(job #29504)

Utilizator shadowman_cosminParaschiv Cosmin shadowman_cosmin Data 9 martie 2007 15:15:33
Problema Factorial Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.75 kb
var f,g:text;
    nat,x,p,a,b:longint;
    c:real;
    ok:boolean;

function putere(m:real):longint;
var put:longint;
begin

put:=0;
while m>0 do
 begin
  put:=put + trunc(m) div 5;
  m:=trunc(m) div 5;
 end;
putere:=put;

end;

begin

assign(f,'in.txt');reset(f);
assign(g,'out.txt');rewrite(g);
readln(f,p);
a:=0;
b:=20000*100000;
ok:=false;

if p=0 then write(g,'1') else
if p=1 then write(g,'5') else
if p>=2 then
while a<b do
 begin
  c:=(a+b)/2;
  x:=putere(c);
  if x=p then
   begin
    nat:=trunc(c) - trunc(c) mod 5;
    writeln(g,nat);
    a:=b+1;
    ok:=true;
   end;
  if x<p then a:=trunc(c)+1;
  if x>p then b:=trunc(c)-1;
 end;

if (p>=2) and (ok=false) then writeln(g,-1);

close(f);
close(g);
end.