#P1009. High Precision Factorial Sum
High Precision Factorial Sum
High Precision Factorial Sum
Given a positive integer n (with n ≤ 50
), compute the sum
\( S = 1! + 2! + 3! + \cdots + n! \)
where the factorial !
is 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\).
Your task is to compute S using high precision arithmetic to handle very large numbers.
inputFormat
The input consists of a single integer n
(1 ≤ n ≤ 50
).
outputFormat
Output the high precision result of the sum \( S = 1! + 2! + \cdots + n! \).
sample
1
1