#include
using namespace std;
int factor(int *Array,int n)//递归计算阶层
{
if(!Array[n])//记录值,减少递归层数
{
return Array[n];
}
else
{
if(n==0||n==1)
{
Array[n]=1;
return 1;
}
else
{
Array[n]=n*factor(Array,n-1);
return Array[n];
}
}
}
int main()
{
int i=0,n=0,sum=0;
cin>>n;
int *Array=new int[n+1];
for(i=1;i
sum+=factor(Array,i);//计算1!+2!+3!+···+n!
}
cout<
}
var:
a:longint;
n,l:integer;
function FACTOR (m:integer):longint;
var
b:integer;
max:longint;
begin
max:=1;
for b:=2 to m do max:=max*b;
FACTOR:=max;
end;
begin
readln(n);
a:=0;
for l:=1 to n do a:=a+FACTOR(l);
writeln(a);
end.
如果数据过大把longint改为int64
再大用高精
Public Function Factor(n As Long) As Long
Dim i As Long, j As Long, k As Long
j = 1
For i = 1 To n: j = j * i: k = k + j: Next
Factor = k
End Function