Pagini recente » Cod sursa (job #2169365) | Cod sursa (job #1123725) | Cod sursa (job #159166) | Cod sursa (job #1446965) | Cod sursa (job #1075638)
program fact;
label 1;
var p,n,i,j,m:qword;
gasit:boolean;
function nrz(n:qword):qword;
var k,i:qword;
begin
i:=5; k:=0;
while n div i<>0 do
begin
inc(k,n div i);
i:=i*5;
end;
nrz:=k;
end;
begin
assign(input,'fact.in');
reset(input);
assign(output,'fact.out');
rewrite(output);
readln(p);
if p=0 then begin write(1); goto 1; end;
i:=1;
j:=1000000000;
gasit:=false;
while (i<=j) and not gasit do
begin
n:=(i+j) div 2;
if nrz(n)=p then gasit:=true
else if nrz(n)>p then j:=n-1
else i:=n+1;
end;
if gasit then begin
while n mod 5<>0 do dec(n);
writeln(n)
end
else
writeln(-1);
1: close(output);
end.