Pagini recente » Cod sursa (job #58436) | Cod sursa (job #604790)
Cod sursa(job #604790)
var st,mij,dr,n:longint;
f,g:text;
function ecuatie(x:longint):longint;
var s,aux:longint;
begin
aux:=1;
s:=0;
while x>=aux do
begin
aux:=aux*5;
s:=s+(x div aux);
end;
ecuatie:=s;
end;
begin
assign(f,'fact.in');
reset(f);
assign(g,'fact.out');
rewrite(g);
read(f,n);
if n=0 then write(g,1) else
begin
st:=1;
dr:=5*n;
while st<>dr do
begin
mij:=(st+dr) div 2;
if ecuatie(mij)>n then dr:=mij-1 else
if ecuatie(mij)<n then st:=mij+1 else
if ecuatie(mij)=n then dr:=mij;
end;
if ecuatie(st)<>n then write(g,-1) else
write(g,st);
end;
close(f);
close(g);
end.