#P1009. [NOIP 1998 普及组] 阶乘之和

[NOIP 1998 普及组] 阶乘之和

Description

Compute with arbitrary-precision integers the value S=1!+2!+3!++n!S = 1! + 2! + 3! + \cdots + n! (n50n \le 50).

Here, ! denotes factorial, defined as n!=n×(n1)×(n2)××1n!=n\times (n-1)\times (n-2)\times \cdots \times 1. For example, 5!=5×4×3×2×1=1205! = 5 \times 4 \times 3 \times 2 \times 1=120.

Input Format

A positive integer nn.

Output Format

A positive integer SS, the result of the computation.

3

9

Hint

【Constraints】

For 100%100 \% of the testdata, 1n501 \le n \le 50.

【Additional Notes】

Note: The book “深入浅出基础篇” uses this problem as an example, but its constraint is only n20n \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