#K8226. Product Except Self
Product Except Self
Product Except Self
You are given an array of integers. For each element in the array, compute the product of all the other elements and output the resulting array.
Formally, given an array \(A\) of length \(n\), construct an array \(B\) such that:
\(B[i] = \prod_{j=0, j\neq i}^{n-1} A[j]\)
Please note:
- If the array has only one element, output 1.
- The input array may contain zeros and negative numbers.
Your program should read from standard input and write to standard output.
inputFormat
The first line of input contains a single integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single line containing \(n\) space-separated integers, where the \(i\)-th integer is the product of all elements of the input array except the \(i\)-th element.
## sample4
1 2 3 4
24 12 8 6