#C4706. Product of Array Except Self

    ID: 48274 Type: Default 1000ms 256MiB

Product of Array Except Self

Product of Array Except Self

Given an integer array nums of length \( n \), construct a new array result such that for each index \( i \),

\[ result[i] = \prod_{\substack{0 \le j < n \\ j \neq i}} nums[j] \]

You must solve this problem without using the division operation. This problem tests your ability to perform aggregate computations efficiently while handling edge cases such as arrays with one element, arrays containing negative numbers, and arrays with repeated elements.

Example:

Input: 4
       1 2 3 4
Output: 24 12 8 6

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains an integer \( n \) which represents the number of elements in the array. The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

The output should be printed to standard output (stdout) in a single line. It should contain \( n \) space-separated integers, where the \( i^{th} \) integer is the product of all elements in the input array except \( nums[i] \).

## sample
4
1 2 3 4
24 12 8 6

</p>