Pagini recente » Cod sursa (job #1155720) | Cod sursa (job #4401) | Cod sursa (job #2771097) | Cod sursa (job #2964102) | Cod sursa (job #29719)
Cod sursa(job #29719)
{$I-,OBJECTCHECKS-,Q-,R-,S-}
program factorial;
const v:array[1..12] of longint=
(5, 25, 125, 625, 3125, 15625, 390625, 1953125, 9765625, 9765625, 244140625, 1220703125);
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.