Pagini recente » Cod sursa (job #1917350) | Cod sursa (job #231143) | Cod sursa (job #868585) | Cod sursa (job #1448924) | Cod sursa (job #195614)
Cod sursa(job #195614)
var f,g:text;
a,b,p,c: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:=3;
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:=10000000;
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);
break;
end;
end;
if a>b then writeln(g,'-1');
close(f);
close(g);
end.