Quantum Cats

If $$$N$$$ is an odd number, simply write in cell $$$i,j$$$ the number $$$((i + j - 2) \cdot \text{inv2modN}) \mod N + 1$$$, where $$$\text{inv2modN} = (N + 1)/2$$$ — the number that is the multiplicative inverse of 2 modulo $$$N$$$, meaning $$$(2 \cdot \text{inv2modN}) \mod N = 1$$$.

Filling $$$(i + j - 2) \mod N + 1$$$ will give a correct arrangement without considering the diagonal constraint, as addition modulo $$$N$$$ forms a group. Multiplying by $$$\text{inv2modN}$$$ will correct the diagonal, as without moduli $$$(i+i)/2=i$$$.

Let's solve the problem for even $$$N$$$. If $$$N = 2$$$, then the arrangement does not exist; for other even $$$N$$$, it does exist.

Imagine we have $$$N/2$$$ variants of blocks of two numbers of size 1 by 2, which can be mirrored. We number each variant from 1 to $$$N/2$$$ and place the numbers $$$i$$$ and $$$i + N/2$$$ in the $$$i$$$-th variant of the block.

These blocks need to tile an $$$N$$$ by $$$N$$$ square. There will be $$$N$$$ blocks in height and $$$N/2$$$ in width. Consider a template of blocks with consecutive numbers from 1 to $$$N/2$$$. We fill the first and second rows with this template. Then we perform a cyclic shift of the template to the left and fill the next two rows. And so on until the end of the table. An example of the resulting table for $$$N = 6$$$ can be seen in the figure (a). Next, we will perform a cyclic shift of the entire table upwards (see figure (b)).

Then we will go through the cells of the table on the diagonal, see which block they belong to, and reflect the corresponding block so that the desired number appears on the diagonal. In the example, the first block remains unchanged (see figure (c)), while the second is reflected (see figure (d)). The result of the diagonal traversal can be seen in figure (e), with unreflected blocks colored green and reflected ones colored blue. After this, we will go through all the other blocks and reflect those blocks whose variants have already appeared above with the same reflection. The final result can be seen in figure (f).

The initial arrangement of blocks guarantees that in each row, each number from 1 to $$$N$$$ appears exactly once, and each variant of the block appears exactly twice in each column. Therefore, through reflections, we can always ensure that in each column, each number from 1 to $$$N$$$ appears exactly once. The initial choice of pairs of numbers for the blocks and the arrangement guarantees that there will always be a block with the desired number on the diagonal.