table with n rows and m columns. Build a table of the same size where cell [i][j] holds the product of every number in table except table[i][j], taken modulo 12345.
Note that 12345 is not prime, so you cannot simply divide the total product by the cell's own value under the modulus. Aim for O(n · m).table=[[2, 5], [3, 1]] → [[15, 6], [10, 30]]
Top left: 5 · 3 · 1 = 15, top right: 2 · 3 · 1 = 6, bottom row: 2 · 5 · 1 = 10 and 2 · 5 · 3 = 30. All are below 12345, so the remainder leaves them unchanged.
table=[[12345, 7, 4]] → [[28, 0, 0]]
The first cell gets 7 · 4 = 28. Both other products include the factor 12345, so their remainder is 0.
table=[[6], [9]] → [[9], [6]]
mtable=[[2, 5], [3, 1]]
[[15, 6], [10, 30]]
Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.