If A and B are $n \times n$ matrices where each column sums to p. Then for what values of p will the matrix AB also have all columns that sum to p?

Nice question.

You can go for the following approach : note that if $A,B$ are $n \times n$ matrices, each having columns summing to $p$, then the sum of all entries of $A$ and $B$ are both $np$ (number of columns times sum of each column).

Now, we calculate the sum of all entries of $AB$. $$ \sum_{i,j=1}^n (AB)_{ij} = \sum_{i,j,k=1}^n A_{ik}B_{kj} = \sum_{j,k=1}^n B_{kj} \sum_{i=1}^n A_{ik} \\ = p \sum_{j,k = 1}^n B_{kj} = np^2 $$

where we note that $\sum_{i=1}^n A_{ik}$ is the sum of the $k$th column of $A$ which is $p$, and that $\sum_{j,k=1}^n B_{jk}$ is the sum of every entry of $B$, which is $np$.

Finally, suppose every column of $AB$ summed to $q$. Note that the sum of all entries of $AB$ is then $nq$. But we've seen it is $np^2$ above.

Therefore, $q = p^2$. In particular, if all columns of $AB$ summed to $p$, then $p = p^2$.

Which forces $p=0$ or $p=1$. I leave you to find matrices $A,B$ such that

  • $A,B,AB$ have every column summing to $0$.

  • $A,B,AB$ have every column summing to $1$.

Think simple, the examples are easy!