Solution (source code)

= Solution

Repeatedly applying the previous product rule gives
$$
\boxed{(B^p)_{ij}=\begin{cases}(B_{ii})^p&i=j,\\0&i\ne j.\end{cases}}
$$
Formally, the result holds for $p=1$; multiplication by $B$ preserves the zero <off-diagonal matrix entries> and multiplies each <diagonal matrix entry> by $B_{ii}$, proving the induction step.