By induction: $ $ no $\,p^2\mid n\,\Rightarrow\, n = n\cdot 1^2,\ $ else induct $\,\ \begin{align}{n/p_i^2 = mk^2\\ {\rm no}\ \ p^2\mid m}\quad \end{align}\ $ so $\ n = m(p_ik)^2$
Remark $\ $ The proof works not only for the set of squares but for any set $\,S\subset \Bbb N_{>0}\,$ that is closed under $\rm\color{#0a0}{ multiplication}$ and contains $\,\color{#c00}1\,$ (i.e. any monoid). Indeed
By induction: $ $ no $\,s\mid n\,\Rightarrow\, n = n\cdot\color{#c00} 1,\ $ else induct $\,\ \begin{align}{n/s_i = ms_j\\ {\rm no}\ \ s\mid m}\quad \end{align}\ $ so $\ n = m(\color{#0a0}{s_i s_j})$