#C4292. Product of Array Except Self
Product of Array Except Self
Product of Array Except Self
Given an array of n integers, compute a new array such that each element at index i is equal to the product of all the numbers in the original array except the one at i. You are not allowed to use the division operator in your solution.
Formally, if the input array is \(a = [a_1, a_2, \dots, a_n]\), then you need to output an array \(b = [b_1, b_2, \dots, b_n]\) where:
\(b_i = \prod_{\substack{j=1 \\ j\neq i}}^{n} a_j \)
Read the input from stdin and write the output to stdout as specified in the input/output sections below.
inputFormat
The first line contains an integer n, the number of elements in the array. The second line contains n space-separated integers representing the array.
outputFormat
Print a single line containing n space-separated integers. The i-th integer should be the product of all the elements in the array except the element at position i.## sample
4
1 2 3 4
24 12 8 6