Let $M_{1}$, $M_{2}$ be two $n \times n$ matrices with entries in $\mathbb{Z}$ such that $\det(M_{1})=\det(M_{2}) = p_{1}p_{2}\cdots p_{m}$, where $p_{j}$ are distinct prime numbers. I need to show that there exist two invertible matrices $A,B$, with entries in $\mathbb{Z}$ such that $M_{1} = A M_{2}B$. If the primes are not distinct then the conclusion may not hold, what could be an example of it?
I now that if above statement holds then $\det(M_{1}) = \det(A M_{2} B)$, and then $\det(B) = 1/\det(A)$, then $B = A^{-1}$. Also since $\det(M_i)$ is not zero, then $M_{i}$ is invertible.
Any hints would be helpful.
Thanks
If $M\in M_n(\mathbb Z)$ is such that $\det M=p_1\cdots p_n$ with $p_i$ distinct primes, then its Smith normal form is necessarily $\operatorname{diag}(1,\dots,1,p_1\cdots p_n)$. This shows the first part of your question.
For the second part consider two diagonal $2\times 2$ matrices, one of them being $\operatorname{diag}(1,p^2)$, and the other $\operatorname{diag}(p,p)$.