Pagini recente » Cod sursa (job #2559888) | Cod sursa (job #3004303) | Cod sursa (job #550105) | Cod sursa (job #3281002) | Cod sursa (job #51311)
Cod sursa(job #51311)
Program factorial;
Var f:text;
p,a,b,c,z:longint;
function zero(c:longint):longint;
var j,zer:longint;
begin
zer:=0;
j:=1;
repeat
j:=j*5;
zer:=zer+(c div j);
until(j*5>c);
zero:=zer;
end;
Begin
assign(f,'fact.in');
reset(f);
readln(f,p);
close(f);
if p<>0 then
begin
a:=1;
b:=1000000000;
repeat
c:=a+((b-a) div 2);
z:=zero(c);
if z<p then a:=c+1;
if z>p then b:=c-1;
until((z=p) or (a>b))
end;
assign(f,'fact.out');
rewrite(f);
if p=0 then Writeln(f,'1')
else
begin
if z=p then Writeln(f,(c div 5)*5);
if a>b then Writeln(f,'-1');
end;
close(f);
End.