a) Let's fill the top left (n−1)×(n−1) subtable arbitrarily; this can be done in 6(n−1)2 ways. Now there are 3 ways to fill each of the top n−1 cells of the rightmost column and 2 ways to fill each of the left n−1 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 2 by the bottom row, and mod 3 by the rightmost column). In conclusion, there are 6(n−1)2⋅3n−1⋅2n−1=6n2−n ways to fill the table.
b) For n=1, the only solution is writing 0 into the single cell. For n=2, let a be the top left number. The bottom right must then be (6−a) mod 6. Using the conditions for rows and columns, for the top right number x we get the equations x≡−a(mod2) and x≡a(mod3), and for the bottom left number y, y≡a(mod2) and y≡−a(mod3). The Chinese remainder theorem determines x and y uniquely, and we see from the equations that their sum is also divisible by 6. Thus there are 6 ways to fill the table in this case, one for each value of a.
Consider now n≥3. Fill the top left (n−1)×(n−1) subtable arbitrarily; this can be done in 6(n−1)2 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 a, the sum of the 2nd to (n−1)-st cells (inclusive) in the top row by b, the sum of the 2nd to (n−1)-st cells in the leftmost column by c, and the sum of 2nd to (n−1)-st cells on the rising diagonal by d.
Using the Chinese remainder theorem, fill the top right cell with the unique value x such that x≡−a−b(mod2) and x≡a+c−d(mod3), and the bottom left cell with the unique value y such that y≡a+b−d(mod2) and y≡−a−c(mod3). The divisibility conditions are now fulfilled for the top row, the leftmost column and both diagonals (the rising diagonal is verified by summing mod 2 and mod 3 separately).
Now, we leave one cell both in the rightmost column and in the bottom row empty for the time being. For the other n−3 empty cells in the rightmost column, there are 3 possible values for each, and for the other n−3 empty cells in the bottom row, 2 values for each. Having made all those choices (which can be done in 3n−3⋅2n−3 ways), the values for the two remaining cells are now uniquely determined (mod 2 by the values in the respective row, and mod 3 by the column). The total number of ways to fill the table is 6(n−1)2⋅3n−3⋅2n−3=6n2−n−2.