Pagini recente » Cod sursa (job #2132051) | Cod sursa (job #611366) | Cod sursa (job #1741005) | Cod sursa (job #553577) | Cod sursa (job #139065)
Cod sursa(job #139065)
var fi,fo:text;
p,x,rez:int64;
function calculate(n:int64):int64;
var i,ct:int64;
begin
i:=5; ct:=0;
while i<=n do
begin
ct:=ct + (n div i);
i:=i*5;
end;
calculate:=ct;
end;
function binars(st,dr:int64):int64;
var mij,aux,aux2:int64;
begin
while st<=dr do
begin
mij:=(st+dr) shr 1;
aux:=calculate(mij);
if aux=p then
begin
binars:=mij;
exit;
end
else
if aux>p then dr:=mij+1
else st:=mij-1;
end;
binars:=-1;
end;
begin
assign(fi,'fact.in'); reset(fi);
assign(fo,'fact.out'); rewrite(fo);
read(fi,p);
if p=0 then writeln(fo,1)
else
begin
rez:=binars(1,2000000000);
if rez=-1 then writeln(fo,-1)
else
begin
if rez mod 10<5 then rez:=(rez div 10)*10
else rez:=(rez div 10)*10+5;
if rez=0 then rez:=1;
writeln(fo,rez);
end;
end;
close(fi);
close(fo);
end.