Let p and q be odd. The recurrence relation gives a2=p and a3=p2−q. Therefore a0 and a3 are even. Since
a3k+3=pa3k+2−qa3k+1=p(pa3k+1−qa3k)−qa3k+1=(p2−q)a3k+1−pqa3k
and the number p2−q is even, we prove by induction that a3k is even for every k≥0, a contradiction.
Let us suppose now that q=2. Then p≥3, since otherwise every an, n≥2, is even. We shall prove by induction that an+1>an≥0 for n≥0, i.e. an>0 for every n≥1, which is a contradiction. The assertion is obvious for n=0. Assume that it follows for n=k, i.e. ak+1>ak≥0. Then we have
ak+2=pak+1−ak=(p−2)ak+1+2(ak+1−ak)>ak+1>0,
hence ak+2>ak+1>0. It remains to consider the case p=2,q>2. It follows by the recurrence relation that we have an+2≡2an+1(modq) for n≥0 and we conclude by induction that an+1≡2n(modq). Then we have −3=a3k≡23k−1(modq). On the other hand, the recurrence relation gives an+2≡2an+1−an(modq−1). Hence
an+2−an+1≡an+1−an≡⋯≡a1−a0=1(modq−1),
i.e. an+1≡n+1(modq−1) for n≥0. Then −3=a3k≡3k(modq−1) and the Little Fermat's theorem gives that 23k+3≡1(modq). Thus 1≡23k+3≡16⋅23k−1≡−48(modq), i.e. q=7. In this case we have a3=22−7=−3 and the required prime numbers are p=2 and q=7.