The first term of the $G.P.$ is $a$ and the $n^{\text{th}}$ term is $b$.
Therefore,the $G.P.$ is $a, ar, ar^{2}, ar^{3}, \dots, ar^{n-1}$,where $r$ is the common ratio.
$b = ar^{n-1}$ .........$(1)$
$P = \text{Product of } n \text{ terms}$
$P = (a)(ar)(ar^{2}) \dots (ar^{n-1})$
$P = (a \times a \times \dots \times a)(r \times r^{2} \times \dots \times r^{n-1})$
$P = a^{n} r^{1 + 2 + \dots + (n-1)}$ .........$(2)$
Here,$1, 2, \dots, (n-1)$ is an $A.P.$
Sum of $n-1$ terms $= \frac{(n-1)}{2} [1 + (n-1)] = \frac{n(n-1)}{2}$.
$P = a^{n} r^{\frac{n(n-1)}{2}}$
Squaring both sides:
$P^{2} = (a^{n} r^{\frac{n(n-1)}{2}})^{2} = a^{2n} r^{n(n-1)}$
$P^{2} = (a^{2} r^{n-1})^{n}$
$P^{2} = (a \cdot ar^{n-1})^{n}$
Using $(1)$,$P^{2} = (ab)^{n}$.
Thus,the result is proved.