Cod sursa(job #1199184)
Utilizator | Reality cojocarugabi | Data | 18 iunie 2014 15:27:56 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.9 kb |
var p,n:qword;
i,j:qword;
k,l:qword;
aux:qword;
function ok(k,l:qword):qword;
var p,i:qword;
begin
p:=1;
i:=0;
while (i<l) do begin
p:=p*k;
inc(i);
end;
ok:=p;
end;
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);
halt(0);
end;
n:=p*4;
k:=0;
while (k<p) do begin
j:=1;
i:=ok(5,j);
aux:=0;
while (n div i<>0) do begin
aux:=aux+(n div i);
inc(j);
i:=ok(5,j);
end;
k:=aux;
inc(n);
end;
if (k=p) then writeln(n-1) else writeln(-1);
close(output);
end.