提交时间:2024-08-20 21:40:12
运行 ID: 173576
#include<iostream> #include<string.h> using namespace std; #define h 250000 char print[h] = { '1' }; int num1[h] = { 0 }, num2[h] = { 0 }; void fact(int n) { int ans[h] = { 0 }; int len1 = 0, sumlen,k = 0; len1 = strlen(print); for (int i = len1 - 1; i >= 0; i--)num1[k++] = (print[i] - '0'); k = 0; while (n) { num2[k++] = n % 10; n /= 10; } for (int i = 0; i < len1; i++) { for (int j = 0; j < k; j++) { ans[j + i] += num1[i] * num2[j]; } } sumlen = len1 + k; k = 0; for (int i = 0; i < sumlen; i++) { if (ans[i] >= 10) { ans[i + 1] += ans[i] / 10; ans[i] = ans[i] % 10; } } while (!ans[sumlen])sumlen--; for (int i = sumlen; i >= 0; i--)print[k++] = ans[i] + '0'; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { fact(i); } cout << print; }