Back
Close

Selective Multiplication

Statement

 Goal

You are given n integers separated by space. For each element (integer), you must output the product of every other element than the current element. This must be done in order ( 1st number in output should be the product of every integer provided except the 1st, etc., )

Example:

Input :
4
1 2 3 4

Thought process :

For 1 : 2*3*4 = 24
For 2 : 1*3*4 = 12
For 3 : 1*2*4 = 8
For 4 : 1*2*3 = 6

Output :
2 0 0
Input
Line 1: An integer n declaring the amount of elements in the next line.
Line 2: n integers separated by spaces.
Output
Line 1: n product of every element except one (ordered by the index of the excluded element), separated by spaces.
Constraints
Every integer provided in line 2 is unique.
At least 2 integers in second line, n ≥ 2.
Output integers fit in 64-bit signed int type.
Example
Input
4
1 2 3 4
Output
24 12 8 6

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1 Test
Input
4 1 2 3 4
Output
24 12 8 6

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

Test 2 Test
Input
3 15 0 3
Output
0 45 0

Validator 2 Validator
Input
3 5 0 6
Output
0 30 0

Test 3 Test
Input
3 88 888 8888
Output
7892544 782144 78144

Validator 3 Validator
Input
3 99 999 9999
Output
9989001 989901 98901

Test 4 Test
Input
3 10 101 1010
Output
102010 10100 1010

Validator 4 Validator
Input
3 1 101 10101
Output
1020201 10101 101

Test 5 Test
Input
3 2147000 27 999999999
Output
26999999973 2146999997853000 57969000

Validator 5 Validator
Input
3 999999999 27 2147000
Output
57969000 2146999997853000 26999999973

Test 6 Test
Input
2 0 2
Output
2 0

Validator 6 Validator
Input
2 1 0
Output
0 1

Test 7 Test
Input
9 1 2 3 4 5 6 7 8 9
Output
362880 181440 120960 90720 72576 60480 51840 45360 40320

Validator 7 Validator
Input
9 20 30 40 5 6 7 8 9 10
Output
181440000 120960000 90720000 725760000 604800000 518400000 453600000 403200000 362880000

Test 8 Test
Input
3 -1 20 30
Output
600 -30 -20

Validator 8 Validator
Input
3 -999 100 -50
Output
-5000 49950 -99900

Test 9 Test
Input
6 1 -2 3 -4 5 -6
Output
-720 360 -240 180 -144 120

Validator 9 Validator
Input
6 -1 2 -3 4 -5 6
Output
720 -360 240 -180 144 -120

Solution language

Solution

Stub generator input