Pagini recente » Cod sursa (job #1289624) | Cod sursa (job #1396352) | Rating Mircea Andrei Bejan (MirceaBejan) | Cod sursa (job #1784306) | Cod sursa (job #139038)
Cod sursa(job #139038)
var fi,fo:text;
p,x,rez:longint;
function calculate(n:longint):longint;
var i,ct:longint;
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:longint):longint;
var mij,aux,aux2:longint;
begin
while st<=dr do
begin
mij:=(st+dr)shr 1;
aux:=calculate(mij);
if aux=p then
begin
dr:=mij+1;
aux2:=calculate(mij-1);
if aux2<>p then
begin
binars:=mij;
exit;
end;
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(0,2000000000);
writeln(fo,rez);
end;
close(fi);
close(fo);
end.