| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91876 | sh25_shenpy | 阶乘计算 | C++ | 通过 | 3 MS | 304 KB | 1015 | 2026-06-17 20:55:48 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { // 优化IO ios::sync_with_stdio(false); cin.tie(NULL); int n; if (!(cin >> n)) return 0; // 使用 vector 存储大整数,低位在前 // 初始值为 1 vector<int> A; A.push_back(1); for (int k = 2; k <= n; ++k) { int carry = 0; // 进位 // 遍历当前大整数的每一位 for (size_t i = 0; i < A.size(); ++i) { int product = A[i] * k + carry; A[i] = product % 10; // 当前位保留个位 carry = product / 10; // 更新进位 } // 处理剩余的进位 while (carry > 0) { A.push_back(carry % 10); carry /= 10; } } // 输出结果:高位在后,所以需要逆序输出 for (auto it = A.rbegin(); it != A.rend(); ++it) { cout << *it; } cout << endl; return 0; }