#K68452. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an array of integers, construct a new array such that each element in the new array is the product of all the numbers in the original array except the one at the corresponding index. More formally, for an array \(a_0,a_1,\dots,a_{n-1}\), you need to compute an array \(b\) where
\(b_i = \prod_{\substack{0 \leq j < n \\ j \neq i}} a_j\)
The solution should read input from stdin and write the result to stdout. If the input array is empty, output an empty line. Note that the input will be given as two lines: the first line contains an integer \(n\) denoting the number of elements, and the second line contains \(n\) space-separated integers.
inputFormat
The first line contains a single integer \(n\) indicating 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 representing the resulting array where the \(i\)-th integer is the product of all the input elements except the one at index \(i\). If the array is empty (i.e., \(n=0\)), output an empty line.
## sample4
1 2 3 4
24 12 8 6