Cod sursa(job #1180017)

Utilizator vrabievictorvictor vrabie vrabievictor Data 29 aprilie 2014 19:50:08
Problema Factorial Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.45 kb
var m,k,p,u,pp,s,x:int64;
begin
assign(input,'fact.in');reset(input);
assign(output,'fact.out');rewrite(output);
readln(pp);
if pp=0 then writeln(1) else
begin
p:=1;
u:=4000000000000000000;
while (p<=u) do
begin
m:=(u+p)div 2;
x:=m;k:=0;
while x>=5 do
begin
x:=x div 5;
k:=k+x;
end;
if k=pp then p:=u+1 else
if k<pp then p:=m+1 else u:=m-1;
end;
if k=pp then
writeln(m-m mod 5) else writeln(-1);
end;
close(input);close(output);
end.