An grid is labeled with consecutive rows and columns so that it is filled with integers from to , inclusive, and the sum of all of the numbers in row and in column are both divisible by . Find the number of possible distinct grids.
Problem 1478
Official solution
Solution:
We begin by filling the grid formed by rows and columns through with any values, which we can do in ways. Then in column , there is at most way to fill in the square in row , ways for the square in row , down to ways in row . Similarly, there is way to fill in the square in row and column , ways to fill in the square in row and column , etc. Overall, the number of ways to fill out the squares in row or column is , so the number of possible distinct grids is .