#K65772. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an array of integers, your task is to return a new array such that each element at index i is the product of all the numbers in the original array except the one at i. You must achieve this without using division.
For an array \(nums\) of length \(n\), the output element at index \(i\) is defined as:
\(\text{result}[i] = \prod_{j=0, j\neq i}^{n-1} \text{nums}[j]\)
Input is read from standard input (stdin) and output should be written to standard output (stdout). The first line of input contains an integer \(n\) representing the number of elements. The following line contains \(n\) space-separated integers which make up the array. For an empty array, \(n\) will be 0.
inputFormat
The input starts with an integer \(n\) (where \(n \ge 0\)) on a new line, which represents the number of elements in the array. If \(n > 0\), the next line contains \(n\) space-separated integers.
outputFormat
Output the resulting array as space-separated integers on one line. If the input array is empty (i.e., \(n = 0\)), output nothing.
## sample4
1 2 3 4
24 12 8 6