Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
173576 陈熙峻B班 高精度阶乘 C++ 无测评数据 0 0 MS 0 KB 855 2024-08-20 21:40:12

Tests(0/0):


#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; }