Skip to main content
OlympiadHQ

Browse · MathNet

Print

IMO Team Selection Contest II

Estonia counting and probability

Problem

Let be a positive integer. In how many ways can an table be filled with integers from to such that

a) the sum of each row is divisible by and the sum of each column is divisible by ;

b) the sum of each row is divisible by , the sum of each column is divisible by and the sum of each of the two diagonals is divisible by ?
Solution
a) Let's fill the top left subtable arbitrarily; this can be done in ways. Now there are ways to fill each of the top cells of the rightmost column and ways to fill each of the left cells of the bottom row to satisfy the requirements. The value for the last empty cell in the bottom right is then uniquely determined (mod by the bottom row, and mod by the rightmost column). In conclusion, there are ways to fill the table.

b) For , the only solution is writing into the single cell. For , let be the top left number. The bottom right must then be mod . Using the conditions for rows and columns, for the top right number we get the equations and , and for the bottom left number , and . The Chinese remainder theorem determines and uniquely, and we see from the equations that their sum is also divisible by . Thus there are ways to fill the table in this case, one for each value of .

Consider now . Fill the top left subtable arbitrarily; this can be done in ways. The bottom right cell's value is uniquely determined by other values on the falling diagonal. Denote the value in the top left cell by , the sum of the nd to -st cells (inclusive) in the top row by , the sum of the nd to -st cells in the leftmost column by , and the sum of nd to -st cells on the rising diagonal by .

Using the Chinese remainder theorem, fill the top right cell with the unique value such that and , and the bottom left cell with the unique value such that and . The divisibility conditions are now fulfilled for the top row, the leftmost column and both diagonals (the rising diagonal is verified by summing mod and mod separately).

Now, we leave one cell both in the rightmost column and in the bottom row empty for the time being. For the other empty cells in the rightmost column, there are possible values for each, and for the other empty cells in the bottom row, values for each. Having made all those choices (which can be done in ways), the values for the two remaining cells are now uniquely determined (mod by the values in the respective row, and mod by the column). The total number of ways to fill the table is .
Final answer
a) 6^{n^2 - n}; b) if n = 1: 1; if n = 2: 6; if n ≥ 3: 6^{n^2 - n - 2}

Techniques

Recursion, bijectionChinese remainder theorem