思路就是高精度x低精度 + 高精度加法
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<int> B,C;
vector<int> mul(vector<int> A, int b)
{
vector<int> C;
if(b == 0)
C.push_back(0);
else
{
int t = 0;
for(int i = 0; i < A.size(); i ++)
{
t += A[i]*b;
C.push_back(t%10);
t /= 10;
}
while(t)
{
C.push_back(t%10);
t /= 10;
}
}
return C;
}
vector<int> add(vector<int> A, vector<int> B)
{
int t = 0;
vector<int> C;
for(int i = 0; i < A.size() || i < B.size(); i ++)
{
if(i < A.size())
t += A[i];
if(i < B.size())
t += B[i];
C.push_back(t %10);
t /= 10;
}
if(t)
C.push_back(t);
return C;
}
int main()
{
int n;
cin >> n;
if(n==1)
cout << "1";
else
{
C.push_back(1);
B = C;
for(int i = 2; i <= n; i ++)
{
C = mul(C,i);//下一个数的阶乘
B = add(B,C);//累加
}
for(int i = B.size()-1; i>=0;i--)
cout << B[i];
}
return 0;
}