#C4646. Product Except Self

    ID: 48207 Type: Default 1000ms 256MiB

Product Except Self

Product Except Self

Given an array of integers, your task is to compute a new array such that each element at index i is equal to the product of all the elements in the original array except the one at i. In other words, for a given array arr of size n, you need to construct an array result where:

$$result[i] = \prod_{\substack{0 \leq j < n\\ j \neq i}} arr[j]$$

This problem assesses your ability to manage cumulative products efficiently without using division.

inputFormat

The input starts with an integer T denoting the number of test cases. For each test case:

  • The first line contains an integer N, the number of elements in the array.
  • The next line contains N space-separated integers, representing the array elements.

outputFormat

For each test case, output a single line with N space-separated integers where the i-th integer is the product of all the original array's elements except the one at index i.

## sample
2
3
1 2 3
4
4 2 1 5
6 3 2

10 20 40 8

</p>