Let b0=1 and write bn=an+1, n≥1. Clearly, bn+1=bn2+1, n≥0. If n>m≥1, it then follows that an−am=bn−bm=bn−12−bm−12=(bn−1−bm−1)(bn−1−bm−1), so
an−am=bn−bm=(bn−m−b0)k=0∏m−1(bn−m+k+bk).(∗)
a2p−ap=b2p−bp=(bp−b0)k=0∏p−1(bp+k+bk).
As parities of the bn alternate and p is odd, so is each of the factors above. We will prove that the p factors bp+k+bk are pairwise coprime, whence the conclusion.
Let 0≤k<ℓ≤p−1 and let d=gcd(bp+k+bk,bp+ℓ+bℓ). By the preceding, d is odd. Suppose, if possible, that d>1 and let ≡ denote congruence modulo d. Then bp+k≡−bk, so bp+k+1=bp+k2+1≡bk2+1=bk+1. Continuing, bp+k+2=bp+k+12+1≡bk+12+1=bk+2 and so on and so forth all the way up to get bp+ℓ≡bℓ. On the other hand, bp+ℓ≡−bℓ, so 2bℓ≡0. Hence bℓ≡0, as d is odd, so bℓ+1=bℓ2+1≡b0.
Consider any index j in the range 0 through p−1 and use (∗) to get
bj+ℓ+1−bj=(bℓ+1−b0)i=0∏j−1(bℓ+1+i+bi)≡0,
as bℓ+1≡b0, by the preceding paragraph. Hence bj+ℓ+1≡bj. Similarly, bj+2(ℓ+1)≡bj+ℓ+1, then bj+3(ℓ+1)≡bj+2(ℓ+1) and so on and so forth to conclude recursively that the sequence (bn) is periodic modulo d.
Let t be the smallest period of the bn (mod d). Recall that bp+k+1≡bk+1, so t divides p. As p is prime, either t=1 or t=p. The former case is ruled out, as b0=1=2=b1, so t=p.
Hence bk≡bp+k≡−bk, so bk≡0, as d is odd. Recalling that bℓ≡0, it follows that ℓ−k is divisible by p. This is a contradiction, as 0<ℓ−k<p.
Consequently, the p numbers bp+k+bk, k=0,1,…,p−1, are pairwise coprime, as stated. This ends the proof and completes the solution.