Pagini recente » Cod sursa (job #3256529) | Cod sursa (job #363147) | Cod sursa (job #3036450) | Cod sursa (job #1895604) | Cod sursa (job #42105)
Cod sursa(job #42105)
var f1,f2:text;
q,c,cz,s,p:longint;
begin
assign(f1,'fact.in');
assign(f2,'fact.out');
reset(f1);
rewrite(f2);
readln(f1,p);
if p=0 then begin
writeln(f2,1);
close(f1);
close(f2);
halt;
end;
s:=0;cz:=0;
repeat
s:=s+125;
cz:=cz+28;
c:=s;
while (c mod 5=0) and (c>=1) do
begin
cz:=cz+1;
c:=c div 5;
end;
until cz>=p;
if cz=p then writeln(f2,s)
else
begin
q:=s;
c:=s;
while (c mod 5=0) and (c>=1) do
begin
cz:=cz-1;
c:=c div 5;
end;
repeat
s:=s-5;
c:=s;
while (c mod 5=0) and (c>=1) do
begin
cz:=cz-1;
c:=c div 5;
end;
if cz<p then begin
writeln(f2,'-1');
close(f1);
close(f2);
halt;
end;
if cz=p then begin
writeln(f2,s-5);
close(f1);
close(f2);
halt;
end;
until s=q-125;
end;
close(f1);
close(f2);
end.