题解 | #N的阶乘# 最短版本
N的阶乘
https://www.nowcoder.com/practice/f54d8e6de61e4efb8cce3eebfd0e0daa
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main(){
int n;
while(cin >> n){
int a[N] = {0};
a[0] = 1;
int carry = 0;
int len = 1;
int temp = 0;
for(int i = 1;i <= n;i ++){
temp = 0;
for(int j = 0;j < len;j ++){
temp = carry + i * a[j];
a[j] = temp % 10;
carry = temp / 10;
}
while(carry){
a[len ++] = carry % 10;
carry /= 10;
}
}
for(int i = len - 1;i >= 0;i --){
cout << a[i];
}
cout << endl;
}
return 0;
}

