The answer is 11.

**
This section requires Javascript.
**

You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.

Relevant wiki: Quadratic Diophantine Equations - Solve by FactoringAnother approach is as follows. Let $a,b$ be the roots of $x^{2} - px + q = 0$ and $c,d$ be the roots of $x^{2} - qx + p = 0$ . Then by Vieta's we have that

$a + b = p, ab = q, c + d = q, cd = p \Longrightarrow a + b = cd, c + d = ab$

$\Longrightarrow a + b + c + d = ab + cd \Longrightarrow ab - a - b + cd - c - d = 0$

$\Longrightarrow (a - 1)(b - 1) + (c - 1)(d - 1) = 2$ .

Now as both $a + b$ and $ab$ must be positive we must have both $a,b$ as positive integers. Likewise $c,d$ . Thus without loss of generality we can have either (i) $(a - 1)(b - 1) = (c - 1)(d - 1) = 1$ or (ii) $(a - 1)(b - 1) = 0$ and $(c - 1)(d - 1) = 2$ . Since the roots must be distinct we can rule out case (i), leaving us with case (ii) as the only viable option. Again without loss of generality we then set $a = 1, c = 3, d = 2$ , which then gives us $b = c + d = 5$ . Finally we find that $p + q = a + b + c + d = \boxed{11}$ .