Sequence an is defined recursively:
$a_1 = 2$
$a_{n + 1} = {a_n}^2 - a_n + 1$
Prove that $a_i$ and $a_j$, $i \neq j$ are relatively prime.
Hint: Prove that $a_{n + 1} = a_1 a_2 \ldots a_n + 1$ and use Euclid’s theorem.
I came across this on Topcoder algorithm tutorial.I know the proof might be easy but I tried to solve it by creating more terms $ a_{n + 2}, a_{n + 3}$ by substituting $a_{n + 1}$ but that doesn't leads to proof.
For a simple proof, we bypass the hint.
Let $p$ be a prime that divides at least one $a_k$. Let $q$ be the smallest $k$ such that $p$ divides $a_k$. We show by induction on $n$ that $a_{q+n}\equiv 1\pmod{p}$. In particular, $p$ does not divide $a_{q+n}$. So any prime divides at most one of the $a_i$, which implies the $a_i$ are pairwise relatively prime.
Now to the induction proof. For the base case $n=1$, note that $a_{q+1}=a_q^2-a_q+1\equiv 0^2-0+1\pmod{p}$. And if $a_{q+n}\equiv 1\pmod{p}$, then $a_{q+n+1}\equiv 1^2-1+1=1\pmod{p}$.