Is it possible to generate a solution for this? $p^2 + q^2 + r^2 = pqr $ I have seen this problem in a local magazine.
I want to Generate an formula for this for the solutions of this problem
Oh and it's given that 
$$p,q,r \in\mathbb{N} $$
and they can be equal.
 A: Let's try working backwards. Assume the values of p and q are given then:
$$p^2+q^2+r^2=pqr$$
is a quadratic equation in r with solutions:
$$r=\frac{pq\pm\sqrt{p^2q^2-4\left(p^2+q^2\right)}}{2}$$
Notice that the numerator will always be even and positive, if it is an integer. Thus there are two integer solutions for $r$ iff $p^2q^2-4(p^2+q^2)$ is a perfect square. Rewriting gives:
$$p^2q^2-4\left(p^2+q^2\right)=\frac{\left(p^2+q^2\right)^2}{2}-\frac{9}{2}\left(p^2+q^2\right) = k^2$$
Applying the quadratic formula again gives:
$$p^2+q^2=\frac{9\pm\sqrt{81+8k^2}}{2}$$
So we need to find another perfect square:
$$81+8k^2=m^2$$
This is the point where I cheated and used Dario Alpern's solver to find that one solution to this is $k=0,m=9$, and for any k and m that solves the equation, so does $k:=3k+m,\ m:=8k+3m$.
It would be easy to write a computer program, that generates such ks and spews out solutions for $(p, q, r)$ when applicable (when $\frac{9\pm\sqrt{81+8k^2}}{2}$ can be expressed as the sum of two squares).
A: There is no formula. All solutions result from taking a triple that solves the Markov equation
$$ x^2 + y^2 + z^2 = 3xyz  $$
and replacing the triple $(x,y,z)$ by $(3x,3y,3z),$ so $p=3x,$ $q=3y,$ $r=3z.$ There is a simple method for moving from one triple in the Markov tree and reaching a neighboring solution. See tree diagram at http://en.wikipedia.org/wiki/Markov_number
Hmmm. I don't see the description of travel to neighboring triples.
Beginning with
$$  (x,y,z) $$ the (usually three) neighbors are
$$  (3yz-x,y,z), $$
$$  (x,3xz-y,z) $$
$$  (x,y,3xy-z). $$
In all three cases, the three entries are traditionally put into increasing order. 
Note that people on this site generally call the movement step as an example of Vieta Jumping, http://en.wikipedia.org/wiki/Vieta_jumping
In particular, repeating the exact same jump (before putting the entries in order!) gets you back to where you were.
This was all worked out for an arbitrary number of values, A. Huwitz (1907) solving
$$ x_1^2 + x_2^2 + \cdots x_n^2 = a x_1 x_2 \cdots x_n  $$ with all positive integers. For $n=3$ the possible values of my letter $a$ are $a=3,$ the Markov triples, and $a=1,$ answers are $3$ times the Markov triples.  
A: Partial results:
1) Suppose two of them are equal, wlog $q=r$ then we have $p^2=(p-2)q^2$. In particular $p-2$ divides $p^2$ but 
$$
\text{gcd}(p^2,p-2) \le \text{gcd}(p,p-2)^2 \le 2^2
$$
therefore $p-2\le 4$. Moreover $p^2>0 \implies p-2>0$, so that $p \in \{3,4,5,6\}$. If $p=3$ we get $q=r=3$. If $p=4$ or $5$ we have no solutions. If $p=6$ then $q=r=3$.
2) Suppose $r=kq$ for some integer $k \ge 2$. Then $p^2+q^2+k^2q^2=kpq^2$ can be rewritten as
$$
(2p-kq)^2+q^2=0, 
$$
which is impossible.
3) From now on we can assume wlog $p>q>r>0$, and $r\nmid q \nmid p$. Moreover, rewrite the equation as
$$
(2p-qr)^2=q^2r^2-4q^2-4r^2.
$$
so that $(qr)^2-4(q^2+r^2)$ and the two other cyclic relations have to be perfect squares.
