Run ID Author Problem Lang Verdict Time Memory Code Length Submit Time
89847 sh25_shengmy 阶乘和 C++ Accepted 0 MS 252 KB 1656 2026-06-05 14:55:21

Tests(2/2):


#include <iostream> #include <cstring> using namespace std; const int MAXLEN = 200; struct BigInt { int d[MAXLEN]; int len; BigInt() { memset(d, 0, sizeof(d)); len = 1; } void set(int x) { memset(d, 0, sizeof(d)); len = 0; if (x == 0) { len = 1; return; } while (x > 0) { d[len++] = x % 10; x /= 10; } } void print() { for (int i = len - 1; i >= 0; i--) { cout << d[i]; } } };BigInt multiply(const BigInt &a, int b) { BigInt c; int carry = 0; c.len = 0; for (int i = 0; i < a.len; i++) { int temp = a.d[i] * b + carry; c.d[c.len++] = temp % 10; carry = temp / 10; } while (carry > 0) { c.d[c.len++] = carry % 10; carry /= 10; } return c; }BigInt add(const BigInt &a, const BigInt &b) { BigInt c; int carry = 0; int maxlen = max(a.len, b.len); c.len = 0; for (int i = 0; i < maxlen; i++) { int temp = a.d[i] + b.d[i] + carry; c.d[c.len++] = temp % 10; carry = temp / 10; } if (carry > 0) { c.d[c.len++] = carry; } return c; } int main() { int N; cin >> N; BigInt sum; sum.set(0); BigInt fact; fact.set(1); for (int i = 1; i <= N; i++) { if (i > 1) { fact = multiply(fact, i); } sum = add(sum, fact); } sum.print(); cout << endl; return 0; }


Judgement Protocol: