Given $\textrm{gcd}(p,q)=1$, in what cases do positive integers $k$ and $a$ exist for which $k^2 + (2q)^2 = (aq+p)^2$?
I have tried to approach this problem using Euclid's parameterization of Pythagorean triples, obtaining for even $q$:
$aq+p = u^2+v^2$
$q = uv$
$k=u^2-v^2$
However, I am unable to find the cases in which there is a way to select such $u$ and $v$. Any form of help would be greatly appreciated.
(Elevating my comment to an answer)
Given $q$, write any factorization $q=uv$ with $u>v>0$ and $\gcd(u,v)=1$; choose any $a$ such that $aq<u^2+v^2$; let $p=u^2+v^2-aq$; let $k=u^2-v^2$, and you have a solution.