Pagini recente » Cod sursa (job #806744) | Cod sursa (job #1451220) | Cod sursa (job #909721) | Cod sursa (job #57286) | Cod sursa (job #199723)
Cod sursa(job #199723)
const nr=1 shl 30;
var p:longint;
f:text;
function nr5(x:longint):longint;
var k:longint;
begin
k:=0;
while x>0 do begin inc(k,x div 5); x:=x div 5; end;
nr5:=k;
end;
procedure cb(x:longint);
var i,step:qword;
begin
step:=nr;
i:=0;
while step>0 do
begin
if (nr5(i+step)<x) then inc(i,step);
step:=step shr 1;
end;
if nr5(i+1)=p then write(f,i+1) else write(f,-1);
end;
begin
assign(f,'fact.in');
reset(f);
read(f,p);
close(f);
assign(f,'fact.out');
rewrite(f);
cb(p);
close(f);
end.