#C7938. Factorial Tuples
Factorial Tuples
Factorial Tuples
Given a list of non-negative integers, your task is to compute the factorial for each integer and output a tuple (n, n!) for each element in the order they appear in the list.
If any number in the list is negative or not a valid integer, the program should output Error and terminate.
Recall the factorial of an integer \(n\) is defined as:
\( n! = \begin{cases} 1, & n=0\\ n \times (n-1)! , & n > 0 \end{cases}\)
For example, for the input list [1, 3, 5], the output should be:
(1, 1)\(3, 6)\(5, 120)
inputFormat
The input is read from standard input (stdin) in the following format:
- An integer \(n\) representing the number of elements in the list.
- A line containing \(n\) space-separated values. Each value should be a non-negative integer.
If any of the \(n\) values is negative or not an integer, the program should output Error (without quotes) and terminate.
outputFormat
For a valid input, the output is written to standard output (stdout) as \(n\) lines. Each line contains a tuple in the format (number, factorial) corresponding to an integer from the input and its factorial. If the input is invalid, output a single line containing Error.
## sample3
1 3 5
(1, 1)
(3, 6)
(5, 120)
</p>