#C10696. Product Array Puzzle
Product Array Puzzle
Product Array Puzzle
Given an array (a) of (n) integers, your task is to compute a new array (output) such that for every index (i),
[ output[i] = \prod_{\substack{0 \leq j < n \ j \neq i}} a_j ]
In other words, each element in the output array is the product of all the numbers in the input array except the number at that same position. Note that if the array is empty, you should output an empty line.
You need to read input from standard input and write the result to standard output.
inputFormat
The input consists of two lines. The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers.
outputFormat
Output a single line containing (n) space-separated integers. The (i)-th integer should be the product of all elements of the input array except the element at index (i). Formally, [ output[i] = \prod_{\substack{0 \le j < n \ j \neq i}} a_j ]
If (n = 0), print an empty line.## sample
4
1 2 3 4
24 12 8 6