The proof is trivial when $m=0$. By unique factorization theorem, let $m^2=p_1p_2p_3\cdots p_r$ and $m=q_1q_2q_3\cdots q_s$ where $m>0$. Thus, $p_1p_2p_3\cdots p_r=q_{1}^{2}q_{2}^{2}q_{3}^{2}\cdots q_{s}^{2}$. If there is a prime number $p_j$ for $j=\{1,\cdots,r\}$ that divides $m^2$, $p_j$ must equal to one of the $q_k's$ because a prime number can only be divided by itself or 1. If $p_j$ does not equal to one of the $q_k's$, $m^2$ will not be an integer, a contradiction. Therefore, $m=q_1\cdots q_k\cdots q_s=q_1\cdots p_j\cdots q_s$ and hence $p_j$ divides $m$ as the other product of $q's$ are integers by unique factorization theorem. This proof holds the same when $m<0$ because we can take $-m>0$.
Is this proof ok?