AcWing 3389. N 的阶乘
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int t,n,m,k,l,r,op,x,y;
vector<int> jc[N];
vector<int> tmp;
void solve(){
jc[1].push_back(1);
for(int i = 2;i<N;i++){
for(int&num:jc[i-1]){
jc[i].push_back(num*i);
}
int siz = jc[i].size();
int carry = 0;
for(int j = siz-1;j>=0;j--){
jc[i][j]=jc[i][j]+carry;
carry = jc[i][j]/10;
jc[i][j]%=10;
}
tmp.clear();
while(carry){
tmp.push_back(carry%10);
carry/=10;
}
reverse(tmp.begin(),tmp.end());
jc[i].insert(jc[i].begin(),tmp.begin(),tmp.end());
}
while(cin>>n){
for(int&num:jc[n]){
cout<<num;
}
cout<<"\n";
};
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}