Pagini recente » Istoria paginii planificare/sedinta-20081010 | Cod sursa (job #511838) | Cod sursa (job #851887) | Cod sursa (job #2283152) | Cod sursa (job #195619)
Cod sursa(job #195619)
var f,g:text;
a,b,p,c,t:longint;
function zero(c:longint):longint;
var x,p,d,nr:longint;
begin
dec(c,c mod 5);
x:=c div 5;
p:=25;
d:=p*5;
nr:=2;
while p<=c do begin
if d=p then begin
inc(x,nr);
d:=d*5;
inc(nr);
end
else inc(x,1);
inc(p,25);
end;
zero:=x;
end;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);
a:=1;
b:=100000000;
t:=0;
while (a<=b) do begin
c:=(a+b) div 2;
if zero(c)<p then a:=c+1;
if zero(c)>p then b:=c-1;
if zero(c)=p then begin
writeln(g,c-c mod 5);
inc(t);
break;
end;
end;
if t=0 then writeln(g,'-1');
close(f);
close(g);
end.