题意
用高精度计算出S=1!+2!+3!+…+n!
分析
用高精度来做
const
maxn=1000;
var
sum,a:array[0..maxn]of longint;
n:longint;
procedure init;
begin
readln(n);
a[maxn]:=1;
end;
procedure cf(k:longint);
var
i,s,g:longint;
begin
g:=0;
for i:=maxn downto 1 do
begin
s:=a[i]*k+g;
a[i]:=s mod 10;
g:=s div 10;
end;
end;
procedure add;
var
g,i,s:longint;
begin
g:=0;
for i:=maxn downto 1 do
begin
s:=a[i]+sum[i]+g;
sum[i]:=s mod 10;
g:=s div 10;
end;
end;
procedure main;
var
i:longint;
begin
for i:=2 to n do
begin
cf(i);
add;
end;
end;
procedure print;
var
i,j:longint;
begin
i:=1;
while (i<=maxn)and(sum[i]=0) do inc(i);
for j:=i to maxn do
write(sum[j]);
end;
begin
sum[maxn]:=1;
init;
main;
print;
end.