function Faktorial(chislo: integer): string;
const max_dlina=3000;
var i: integer;
p: array[0..3000] of byte;
procedure Umnozhit(chislo: integer);
var i, k, um: integer;
p1: array[0..max_dlina-1] of integer;
begin
k:=0;
For i:=0 to max_dlina-1 do
p1[i]:=0;
Repeat
k:=k+1;
um:=0;
For i:=max_dlina-1 downto 1 do
If (i>k) then
begin
p1[i-k+1]:=p1[i-k+1]+um+p[i]*(chislo mod 10);
um:=p1[i-k+1] div 10;
p1[i-k+1]:=p1[i-k+1] mod 10;
end;
chislo:=chislo div 10;
Until chislo=0;
For i:=0 to max_dlina-1 do
p[i]:=p1[i];
end;
begin
For i:=0 to max_dlina-2 do
p[i]:=0;
p[max_dlina-1]:=1;
For i:=1 to chislo do
Umnozhit(i);
Result:='';
For i:=0 to max_dlina-1 do
Result:=Result+IntToStr(p[i]);
While (Result<>'') and (Result[1]='0') do
Delete(Result, 1, 1);
end;
где
chislo - исходное число.
Например, Faktorial(10) выведет '3628800'.
|