#C7118. Factorial with Memoization
Factorial with Memoization
Factorial with Memoization
Given a sequence of non-negative integers, compute their factorial using memoization to avoid redundant calculations. The factorial of a number \( n \) is defined as \( n! = n \times (n-1)! \) with the base case \( 0! = 1 \). Efficient computation is required, so make use of caching intermediate results. Read input from standard input and output the result for each test case on a separate line.
inputFormat
The first line contains an integer \( T \) representing the number of test cases. Each of the next \( T \) lines contains a single non-negative integer \( n \) for which you need to compute \( n! \).
outputFormat
For each test case, output the factorial of the given integer \( n \) on a new line.
## sample4
0
1
5
10
1
1
120
3628800
</p>