Pagini recente » Cod sursa (job #2979101) | Cod sursa (job #1189116) | Cod sursa (job #2467634) | Cod sursa (job #3145881) | Cod sursa (job #29721)
Cod sursa(job #29721)
{$I-,OBJECTCHECKS-,Q-,R-,S-}
program factorial;
const v:array[1..16] of longint=
(5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 1220703125, 6103515625, 30517578125, 152587890625, 762939453125);
var n,p,f,s,i:longint;
begin
assign(input,'fact.in');
reset(input);
readln(p);
close(input);
assign(output,'fact.out');
rewrite(output);
if p=0 then begin writeln(1); close(output); exit; end;
n:=p*5;
s:=12;while n/v[s]<1 do dec(s);
//function
for i:=1 to s do
inc(f,trunc(n/v[i]));
while f>p do
begin
dec(n,5);
f:=0;
for i:=1 to s do
inc(f,trunc(n/v[i]));
end;
if p>f then writeln(-1) else writeln(n);
close(output);
end.