On the complete solution to $x^2+y^2=z^k$ for odd $k$? While trying to answer this question, I was looking at a computer output of solutions to $x^2+y^2 = z^k$ for odd $k$ and noticed certain patterns. For example, for $k=5$ we have $x,y,z$,
$$10, 55, 5\\25, 50, 5\\38, 41, 5\\117, 598, 13\\122, 597, 13\\338, 507, 13\\799, 884, 17$$
Question: Is it true that all integer solutions to $x^2+y^2=z^k$ for odd $k>1$ are given by just two formulas, namely,


*

*Primitives $\gcd(x,y)=1$:
$$A^2+B^2 = (a^2+b^2)^k\tag1$$
where $A,B$ is the expansion of $(a+bi)^k = A+Bi$. Example, $$(a+bi)^3 =(a^3 - 3 a b^2)+ (3 a^2 b - b^3)i$$ hence, $$(a^3 - 3 a b^2)^2+ (3 a^2 b - b^3)^2 = (a^2+b^2)^3$$ and so on for other $k$.

*Non-primitives $\gcd(x,y)\neq1$:
$$a^2(a^2+b^2)^{k-1}+b^2(a^2+b^2)^{k-1} = (a^2+b^2)^k\tag2$$
where, for both Forms $1$ and $2$, we use some rational $a,b$?


Example. The first three solutions for $k=5$ above use:
$$a,b = 2/5,\;11/5\quad \text{Form 2}$$
$$a,b = 1,\;2\quad \text{Form 2}$$
$$a,b = -2,\;1\quad \text{Form 1}$$

Good news: the answer is Yes. Moreover, all integer solutions are given by just one formula - the second one. It covers both primitive and non-primitive solutions. That is, for every solution $(x,y,z)$ to $x^2+y^2=z^k$  there exist rational numbers $a,b$ such that $x=a(a^2+b^2)^{(k-1)/2}$, $y=b(a^2+b^2)^{(k-1)/2}$ and $z=a^2+b^2$.
Bad news: This formula is quite useless. The reason is that you use rational parameters to describe integer solutions, and the question for which rational parameters the corresponding values of $x,y,z$ are integers is as difficult as solving the equation.
Now the proof. Take $a=\frac{x}{z^{(k-1)/2}}$, $b=\frac{y}{z^{(k-1)/2}}$. Then $a^2+b^2=(x^2+y^2)/z^{k-1} = z^k/z^{k-1}=z$, $a(a^2+b^2)^{(k-1)/2}=\frac{x}{z^{(k-1)/2}}z^{(k-1)/2}=x$ and $b(a^2+b^2)^{(k-1)/2}=y$.
