TITLE: What is the least value of $k$ for which $B^k = I$?
QUESTION [10 upvotes]: I found the following question in a textbook, and I wasn't able to solve it.

Suppose $A$ and $B$ are two non-singular matrices such that $B \neq I$, $A^6 = I$, and $AB^2 = BA$, then what is the least value of $k$ for which $B^k = I$?

My attempt
We can see that $A^6 = I$, so, I tried to manipulate the second equation to involve $A^6$, so that we can get the identity matrix. But this didn't work, and I ended up getting something of the form, $B^{-1}AB^2 = A$. I wasn't able to reduce it further.
Answer

 The answer is $k = 127$.

REPLY [3 votes]: If we remove the hypothesis $A^6=I_n$...
Proposition. Let $B\in GL_n(\mathbb{C})$ s.t. $B^2$ and $B$ are similar.
Then, there is a positive integer $k$ s.t. $B^k=I_n+N$ where $N$ is nilpotent.
Proof. Let $\sigma(B)$ be the spectrum of $B$ and $\lambda\in \sigma(B)$. Then $\lambda^2,\lambda^{2^2},\cdots\in\sigma(B)$; it is not difficult to deduce that there is $p\leq n$ s.t. $\lambda^{2^p-1}=1$. Let $k=lcm(2-1,2^2-1,\cdots,2^n-1)$. Then, for every $\lambda\in\sigma(B)$, $\lambda^k=1$ and we are done.
Example. If $n=4$, then $k=lcm(1,3,7,15)=105$.
Remark 1. Of course, if $B$ is diagonalizable, then $B^k=I_n$.
EDIT. Remark 2. We assume $A^6=I$ and we search a couple s.t. the order of $B$ is $63$ (maximal). According to the proof above, necessarily, $n\geq 6$ and, in fact, $6$ is convenient. Indeed, let $a=exp(2i\pi/63)$ and take
$B=diag(a,a^2,a^4,a^8,a^{16},a^{32}),A=[a_{i,j}]$ where $A$ is the permutation defined by: the $a_{i,j}$ are $0$ except $a_{i,i+1}=1,a_{n,1}=1$. Then $A^6=I,ABA^{-1}=B^2$.