#B2153. Factorial Sum

    ID: 11235 Type: Default 1000ms 256MiB

Factorial Sum

Factorial Sum

Given a positive integer \( n \), calculate the sum of the factorials of all positive integers not exceeding \( n \). That is, compute:

\[ 1! + 2! + 3! + \cdots + n! \]

The factorial of a number \( n \) 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 \).

inputFormat

The input consists of a single positive integer \( n \) provided on one line.

outputFormat

Output a single integer, the value of \( 1! + 2! + 3! + \cdots + n! \).

sample

3
9