Problem

Source: Tournament of Towns, Junior A-Level , Spring 2019 p5

Tags: square grid, numbers in a table, table, combinatorics



One needs to ffll the cells of an $n\times n$ table ($n > 1$) with distinct integers from $1$ to $n^2$ so that every two consecutive integers are placed in cells that share a side, while every two integers with the same remainder if divided by $n$ are placed in distinct rows and distinct columns. For which $n$ is this possible? (Alexandr Gribalko)