P1009 [NOIP 1998 Junior] Sum of Factorials
Description
Compute with arbitrary-precision integers the value $S = 1! + 2! + 3! + \cdots + n!$ ($n \le 50$).
Here, `!` denotes factorial, defined as $n!=n\times (n-1)\times (n-2)\times \cdots \times 1$. For example, $5! = 5 \times 4 \times 3 \times 2 \times 1=120$.
Input Format
A positive integer $n$.
Output Format
A positive integer $S$, the result of the computation.
Explanation/Hint
【Constraints】
For $100 \%$ of the testdata, $1 \le n \le 50$.
【Additional Notes】
Note: The book “深入浅出基础篇” uses this problem as an example, but its constraint is only $n \le 20$, so the code in the book cannot pass this problem.
To pass this problem, please continue studying the Chapter 8 content on arbitrary-precision (“high-precision”) arithmetic.
NOIP 1998 Junior, Problem 2.
Translated by ChatGPT 5