Solution (source code)

= Solution

$B^k=S^{-1}A^kS$, so the preceding argument applied to $A^k,B^k$ gives equal ranks.