#K88042. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an array \(A\) of \(n\) integers, compute a new array \(B\) such that each element \(B[i]\) is the product of all the numbers in \(A\) except \(A[i]\). Formally, for each index \(i\) (with \(0 \le i < n\)), you need to compute:
\[ B[i] = \prod_{\substack{0 \le j < n \\ j \neq i}} A[j] \]
If \(n = 0\), simply output an empty line. Note that the array may contain zeros or negative numbers. You are not allowed to use division in your solution.
Example:
Input: 4 1 2 3 4</p>Output: 24 12 8 6
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) indicating the number of elements in the array.
- If \(n > 0\), the second line contains \(n\) space-separated integers.
outputFormat
Output to standard output (stdout) a single line containing the resulting array with all elements printed as space-separated integers. If the input array is empty (i.e., \(n = 0\)), output an empty line.
## sample4
1 2 3 4
24 12 8 6