Pagini recente » Cod sursa (job #148490) | Cod sursa (job #3262853) | Cod sursa (job #3159186) | cpa_01 | Cod sursa (job #139053)
Cod sursa(job #139053)
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
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 mod 10<5 then rez:=(rez div 10)*10
else rez:=(rez div 10)*10+5;
writeln(fo,rez);
end;
close(fi);
close(fo);
end.