Pagini recente » Cod sursa (job #2489353) | Cod sursa (job #1461244) | Cod sursa (job #116331) | Cod sursa (job #2320045) | Cod sursa (job #1040849)
program factorial;
uses crt;
var n,p,min,max,mid,val:longint;
u:boolean;
function fact(n:longint):longint;
var k,i:longint;
begin
k:=0;
i:=5;
while (n div i<>0) do begin
k:=k+n div i;
i:=i*5;
end;
fact:=k;
end;
begin
clrscr;
assign(input,'fact.in') ; reset(input);
readln(p) ; close(input);
assign(output,'fact.out') ; rewrite(output);
min:=1;
max:=10000000;
while (min<=max) and (not u) do begin
mid :=(min+max) div 2;
val:=fact(mid);
if val<p then min:=mid+1
else if val>p then max:=mid-1
else u:=true
end;
if u then begin
while mid mod 5<>0 do dec(mid);
write(mid);
end
else write(-1);
close(output);
end.
end.