How to prove $\gcd(a^2, b^2) = (\gcd(a, b))^2$?
My attempt:
Let $\gcd(a, b) = d$.
Then $d|a$ and $d|b$ then $d^2|a^2$ and $d^2|b^2$. i.e $d^2$ divides $a^2 ~~\&~~ b^2$.
How to prove $\gcd(a^2, b^2) = (\gcd(a, b))^2$?
My attempt:
Let $\gcd(a, b) = d$.
Then $d|a$ and $d|b$ then $d^2|a^2$ and $d^2|b^2$. i.e $d^2$ divides $a^2 ~~\&~~ b^2$.
Hint: Factor $a$ and $b$ into primes. If $a=p_1^{n_1}\cdot\ldots\cdot p_k^{n_k}$ and $b=p_1^{m_1}\cdot\ldots\cdot p_k^{m_k}$ with each $n_i,m_i\ge 0$, then
$$\gcd(a,b)=p_1^{\min\{n_1,m_1\}}\cdot\ldots\cdot p_k^{\min\{n_k,m_k\}}.$$
If $\gcd(a,b)=d$, then
$a = a'd$
$b = b'd$
and $\gcd(a',b') = 1$
That means
$a^2 = {a'}^2d^2$
$b^2 = {b'}^2d^2$
and $\gcd({a'}^2,{b'}^2) = 1$ $ ~~\color{red}{ \star }$
Hence $\gcd(a^2,b^2)=d^2$.
$ ~~\color{red}{ \star }$ pelase see this.
$\begin{align}\color{#0af}{(a,b)}(a^2,b^2) =&\ (a^3,a^2b,ab^2,b^3)\quad [\text{by gcd distributive law etc - see Remark below}]\\ =&\ \color{#0af}{(a,b)}^3\end{align}$
Thus $\ (a^2,b^2) = (a,b)^2\ $ by cancelling $\,\color{#0af}{(a,b)} \neq 0.\ \ $ [here is a cubic & higher degree analog]
Or Gauss's Lemma (GL) yields a slick proof. Let $\rm\:{\cal C}(f)\:$ denote the content of a polynomial, i.e. the gcd of its coefficients. Then GL $\rm \Rightarrow {\cal C}(f\:g) \color{#c00}{\overset{\rm GL_{\phantom |}\!}=}\ {\cal C}(f)\ {\cal C}(g)\ $ so
$$\begin{align} (a,b)^2\! &=\ {\cal C}(ax\! +\! b)\ {\cal C}(a x\! -\! b)\, \\[.2em] &\,\smash[]{\color{#c00}{\overset{\rm GL_{\vphantom |}}=}}\, {\cal C}((a x\! +\! b)(ax\! -\! b))\,\\[.2em] &=\, {\cal C}(a^2 x^2\! -\! b^2)\, \\[.2em] &=\, (a^2,b^2)\end{align}$$
Remark we used only basic gcd laws (associative & commutative & distributive), e.g. let's do the gcd analog of the binomial theorem (in detail)
$\ (a,b)^2\! = (a,b)(a,b) = ((a,b)a,(a,b)b) = ((a^2,ba),(ab,b^2)) = (a^2,ba,ab,b^2) = (a^2,ab,b^2)$
Similarly $\,(a,b)^3 = (a,b)(a,b)^2 = (a,b)(a^2,ab,b^2) =\,\cdots\, = (a^3,a^2b,ab^2,b^3)$
By induction $\ (a,b)^n = (a^n, a^{n-1}b,\cdots\,ab^{n-1},b^n)\ $ is straightforwardly proved.
Such gcd arithmetic requires no ingenuity - it is analogous to multiplying polynomials.
The proof generalizes to the Freshman's Dream $\,(a,b)^n = (a^n,b^n)\,$ for gcds and invertible ideals.
I'll use the notation of Michael's answer.
Since $g_2\mid a^2$, $g_2\mid b^2$, $g_1\mid a$ and $g_1\mid b$, there are integers $p,q,r,s$ such that:
$$a^2 = g_2p, \ b^2=g_2q, \ a=g_1r, \ b=g_1s \ ,$$
with $gcd(p,q)=1$ and $gcd(r,s)=1$. Manipulating those expressions, is easy to get that $r^2q=s^2p$ and, by Euclid's lemma, $r^2\mid p$ and $p\mid r^2$ thus $p=r^2$ (assuming positive integers), similarly, $q=s^2$ so finally
$$g_1^2 = \frac{a^2}{r^2}=\frac{g_2p}{r^2} = g_2$$
Here I use that if $gcd(r,s)=1$, then $gcd(r^2,s^2)=1$. This is much easier to prove than the general case so my reasoning is not circular.
Hint (for the easy direction): Suppose that $g_1=\gcd(a,b)$ and $g_2=\gcd(a^2,b^2)$. Since $g_1\mid a$ and $g_1\mid b$, then $g_1^2\mid a^2$ and $g_1^2\mid b^2$. Therefore, by the definition of the greatest common divisor, $g_1^2\mid g_2$.
The other direction can be shown using the ceiling function:
$p^k \mid a^2, b^2 \implies p^{\lceil{\frac{k}{2}\rceil}}\mid a,b \implies p^{\lceil{\frac{k}{2}\rceil}} \mid (a,b) \implies (p^{\lceil{\frac{k}{2}\rceil}})^2 \mid(a,b)^2 \implies p^k \mid (a,b)^2$