Pagini recente » Cod sursa (job #2882077) | Cod sursa (job #3162503) | Cod sursa (job #852599) | Cod sursa (job #303283) | Cod sursa (job #675178)
Cod sursa(job #675178)
program factorial;
var p,n:longint;
f:text;
function zerouri(x:longint):longint;
var cop, sum:longint;
begin
cop:=x;
sum:=0;
while cop>0 do begin
cop:=cop div 5;
sum:=sum+cop;
end;
zerouri:=sum;
end;
procedure binar(a,b:longint);
var c,v:longint;
begin
c:=(a+b)div 2;
v:=zerouri(c);
if (c=a)or(c=b)and(v<>p) then n:=-1 else
if v<p then binar(c, b)
else if v>p then binar(a,c)
else n:=c-(c mod 5);
end;
begin
assign(f,'fact.in'); reset(f);
readln(f,p);
close(f);
binar(1, maxlongint-1);
assign(f,'fact.out'); rewrite(f);
writeln(f,n);
close(f);
end.