Integer Solutions to $x^2+y^2=5z^2$ I'm looking for a formula to generate all solutions $x$, $y$, $z$ for $x^2 + y^2 = 5z^2$.
Any advice?
 A: Presumably you’re looking for solutions from $\mathbb Z$. When you have such a solution, you can divide the equation through by $z^2$ to find rational numbers $\lambda$ and $\mu$ such that $\lambda^2+\mu^2=5$. So far so good. Now you can think of $(\lambda,\mu)$ as the complex number $\lambda+\mu i\in{\mathbb{Q}}(i)$, the field of Gaussian numbers. And, when we call $z=\lambda+\mu i$, the condition is that $\mathbf{N}(z)=5$, where $\mathbf N$ is the norm map, $z\mapsto z\bar z$, which you see is multiplicative. Now, in case $\mathbf{N}(z)=5$ and $\mathbf{N}(u)=1$, you see that $zu$ is another point on your circle of radius $\sqrt5$, just the kind of number you’re looking for.
But we know all the Gaussian numbers of norm $1$, they correspond to Pythagorean triples, just as $5/13 + 12i/13$ corresponds to the Pythagorean triple $(5,12,13)$, and there are various ways of describing these triples, in other words the appropriate Gaussian numbers of norm $1$. Here’s one way of describing all the P-triples:
The Gaussian numbers of norm $1$ are an infinitely generated abelian group. The torsion subgroup is $\{\pm1,\pm i\}$, and, modulo these, the group is free-abelian, generators indexed by the primes congruent to $1$ modulo $4$. For each such prime $p$, you write $p=m^2+n^2$, and the corresponding generator of the above-mentioned free-abelian group is $(m+ni)/(m-ni)$. The upshot is that once you've made your choices of these generators $\{g_p\}$, every Gaussian number of norm $1$ is uniquely writable as $\varepsilon\prod_p g_p^{e_p}$. Here the product must be finite, that is all but finitely many of the exponents $e_p$ must be zero, and the $\varepsilon$ is $\pm1$ or $\pm i$.
Example: take $g_5=(2+i)/(2-i)=(3+4i)/5$. Then, using the fixed Gaussian number $2+i$ for your $z$, if you use $u=g_5^2=(-7+24i)/25$, you get $uz=(-38+41i)/25$. This yields the solution $x=-38$, $y=41$, $z=25$ to your original equation.
A: I couldn't but notice the pattern $x^2 + y^2 = 5 z^2 = z^2 + (2z)^2 $; owing to 
$(am+bn)^2 + (an-bm)^2 = (an+bm)^2 + (am-bn)^2 $, and so if we let $x=am+bn , y=an-bm , z=am-bn$ , we need $an + bm = 2(am-bn)$ , i.e. $ a(n - 2m) + b(m+2n) =0$   which is possible by 
$a = (m+2n) k , b=(2m-n)k $ , where $a,b,m,n,k$ $∈$ $\Bbb Z$
So, the solutions are :- $x = k( m^2 + 4mn - n^2 )$ ; $y = 2k(mn + n^2 - m^2 )$ ; $z = k( m^2 + n^2 )$ these are same as what "dinoboy" seems to have obtained by comparatively more effort.
A: Ok, so I am assuming rational solutions. This method can yield a parametrization of all integer solutions without too much work.
Note that $(1,2)$ lie on the circle $x^2 + y^2 = 5$. Let $x_0 = 1, y_0 = 2$. Now suppose $x^2 + y^2 = 5$. Let $m = x - x_0, n = y - y_0$, then we have $$m^2 + 2mx_0 + x_0^2 + n^2 + 2ny_0 + y_0^2 = 5$$
And thus $m^2 + 2mx_0 + n^2 + 2ny_0 = 0$. Let $\lambda = \frac{m}{n}$. Then we have: $$n^2\lambda^2 + 2n\lambda x_0 + n^2 + 2ny_0 = 0$$
$$n\lambda^2 + 2\lambda x_0 + n + 2y_0 = 0$$
$$n = \frac{-2y_0 - 2\lambda x_0}{1 + \lambda^2}$$
Plugging in $x_0 = 1, y_0 = 2$:
$$n = \frac{-4 - 2 \lambda}{1 + \lambda^2}$$
Thus it follows $$(x,y) = \left (1 + \frac{-4\lambda - 2\lambda^2}{1 + \lambda^2}, 2 + \frac{-4 - 2 \lambda}{1 + \lambda^2} \right )$$
where $\lambda$ is an arbitrary number in $\mathbb{Q}$.
Now for $x^2 + y^2 = 5z^2$, we simply need: $$(x,y,z) = \left (z + \frac{-4z\lambda - 2z\lambda^2}{1 + \lambda^2}, 2z + \frac{-4z - 2z \lambda}{1 + \lambda^2},z \right )$$
If you want solutions in $\mathbb{Z}$, it takes only a little more work to finish.
EDIT: So either I made a massive reading failure or the author changed the title. So here's how to finish.
A slightly neater form to work with is $$(x,y,z) = \left (1 + \lambda^2  -4\lambda - 2\lambda^2, 2 + 2\lambda^2 -4 - 2\lambda, 1 + \lambda^2 \right )$$
Letting $\lambda = \frac{m}{n}$, we see that:
$$(x,y,z) = \left (m^2 - n^2  -4mn, 2n^2 -2m^2 - 2mn, m^2 + n^2 \right )$$
