On the invariant factors of the matrix XAY+B