Pagini recente » Cod sursa (job #1768974) | Cod sursa (job #2380031) | Cod sursa (job #635717) | Cod sursa (job #2444741) | Cod sursa (job #164329)
Cod sursa(job #164329)
var p:longint;
f:text;
function func(n:longint):longint;
var pu,nr,r,i:longint;
begin
r:=0;
pu:=5;
while n div pu>0 do
begin
inc(r,n div pu);
pu := pu * 5;
end;
func:=r;
end;
procedure bin(a,b:longint);
var r,c:longint;
begin
if a>b then
write(f,-1)
else
begin
c:=(a+b) div 2;
r:=func(c);
if r<p then
bin(c+1,b)
else if r>p then
bin(a,c-1)
else if r=p then
write(f,c-(c mod 5));
end;
end;
begin
assign(f,'fact.in');reset(f);
read(f,p);
assign(f,'fact.out');rewrite(f);
if p=0 then
write(f,1)
else
bin(0,p*5);
close(f);
end.