#K4426. Product Except Self
Product Except Self
Product Except Self
In this problem, you are given an array of distinct integers. The task is to compute a new array where the element at each index is the product of all the elements in the original array except for the element at that index. All products should be computed modulo $$10^9+7$$.
For example, given the array [1, 2, 3, 4], the output should be [24, 12, 8, 6] because:
- At index 0: product = 2 * 3 * 4 = 24
- At index 1: product = 1 * 3 * 4 = 12
- At index 2: product = 1 * 2 * 4 = 8
- At index 3: product = 1 * 2 * 3 = 6
If the array contains less than two elements, return an empty list.
The input begins with an integer T indicating the number of test cases. For each test case, the first line contains an integer N denoting the number of elements, followed by a line with N space-separated integers. Your program should process each test case and output the result in a new line.
inputFormat
The input is read from stdin. The first line contains an integer T, representing the number of test cases. Each test case consists of two lines: the first line has an integer N denoting the size of the array, and the second line contains N space-separated integers.
outputFormat
For each test case, output a single line containing N space-separated integers. Each integer is the product of all the array elements except the one at that index, computed modulo $$10^9+7$$. If N < 2, output an empty line.## sample
1
4
1 2 3 4
24 12 8 6
</p>