https://www.luogu.com.cn/problem/P1009
本题为高精度乘法 + 高精度加法
#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 1010; int n; int a[N], b[N]; int main() { cin >> n; a[0] = b[0] = 1; for(int i = 2; i <= n; i ++ ) { for(int j = 0; j < 100; j ++ ) b[j] *= i; for(int j = 0; j < 100; j ++ ) if(b[j] > 9) { b[j + 1] += b[j] / 10; b[j] %= 10; } for(int j = 0; j < 100; j ++ ) { a[j] += b[j]; if(a[j] > 9) { a[j + 1] += a[j] / 10; a[j] %= 10; } } } int res; for(res = 100; res >= 0 && a[res] == 0; res -- ); for(int j = res; j >= 0; j -- ) cout << a[j]; return 0; }