Primes in a list formed by multiplying $5$ by $a$ and adding $b$ 
Take two positive integers $a$ and $b$ that are not multiples of $5.$ Then, construct a list in the following fashion: let the first term be $5,$ and starting with the second number, each number is obtained by multiplying the previous number on the list by $a$ and adding $b.$ What is the maximum number of primes that the list can contain before obtaining the first composite number?


I first started the problem by writing out a couple terms in the sequence:
$$5, 5a + b, 5a^2 + ab + b, 5a^3 + a^2b + ab + b, 5a^4 + a^3b + a^2b + ab + b, \cdots$$
I then tried interpreting each term in modulo $5$ but considering each $a, b \pmod{5}$ and expanding was far too long. Considering the terms in modulo $2$ also didn't work since there always exists a way to make the term $\not\equiv 0 \pmod{2}.$
Is there a better way to try and solve this problem besides grueling casework on $a,b, \pmod{5}$?
 A: Note your sequence is a linear recurrence with constant coefficients, i.e.,
$$n_0 = 5, \; \; n_k = an_{k-1} + b \; \forall \; k \ge 1 \tag{1}\label{eq1A}$$
We could determine $n_k$ explicitly using the method specified in the link, but note instead that, for $a \not\equiv 1 \pmod{5}$, as can be seen from your list of initial values (& can be proven using induction), we have
$$n_k \equiv 5a^k + b\left(\frac{a^k-1}{a-1}\right) \pmod{5} \tag{2}\label{eq2A}$$
By Fermat's little theorem, $a^4 - 1 \equiv 0 \pmod{5}$, so $n_4 \equiv 0 \pmod{5}$. Since $n_4 \gt 5$, it's not a prime and, thus, there's a maximum possible $4$ primes in a row.
For $a \equiv 1 \pmod{5}$, we instead have
$$n_k \equiv 5 + kb \pmod{5} \tag{3}\label{eq3A}$$
Note that $n_k \not\equiv 0 \pmod{5}$ for $1 \le k \le 4$, but that $n_5 \equiv 5 + 5b \equiv 0 \pmod{5}$, so it's not a prime. This shows there's a maximum possible $5$ initial primes in a row. In particular, $a = 1$ and $b = 6$ give an initial list of $5$ primes of $\{5, 11, 17, 23, 29\}$. This proves that $5$ is the maximum initial number of primes in a row possible in your sequence.
A: Though you've accepted an answer a day prior, it's worth strong emphasis that problems like this can be solved more simply (and more generally) using basic ideas about permutation cycles (if these are unfamiliar then see the alternative direct proof in a Remark below). Bringing to the fore the innate $\rm\color{#0a0}{periodic (cycle)}$ structure of the sequence $\!\bmod 5$ yields the very simple proof below.
Proof $\, $ Your sequence $\:\!c_n$ is generated by iteratively applying $\:\!f(x) = ax\:\!\!+\!b\,$ starting at $\,\color{}{c_0 = 5},\,$ i.e. $\,c_n = f^n(c_0).\,$ Viewed $\!\bmod 5\:\!$ note $f\,$ is invertible: $\,f^{-1}(x) \equiv (x\!-\!b)/a,\,$ by $\,a\not\equiv 0,\,$ so $f\,$ is a $\rm\color{#0a0}{permutation}$, and all $\:\!c_k\:\!$ lie in the $\:\!\rm\color{#0a0}{orbit\, ({\it cycle})}$ $f^k(\color{}{c_0})$ of  length at most $\:\!\color{#c00}5 = |\Bbb Z_5|.\,$ So the initial value $\,c_0\equiv 0\pmod{\!5}\,$ repeats as $\,c_k\equiv 0\,$ for $\,0< k\le \color{#c00}5,\,$ so $\,5\mid c_k,\,$ so $\,c_k\,$ is composite (by $c_k$ is increasing so $\,k>0\Rightarrow c_k> c_0\!=\!5).\,$ Thus there are at most $\,\color{#c00}5\,$ initial primes in $\,c_k.\ \ \small\bf QED$

Remark $ $ If permutation cycles are unknown then we can directly prove the needed $\rm\color{#0a0}{periodicity}$.
Lemma $ $ If $f$ is an invertible map on $\Bbb Z_n = \Bbb Z \bmod n$ then $f^k(a)\equiv a\pmod{\! n}\,$ for some $\,k\le n$.
Proof $\, $ Pigeonhole $\Rightarrow$ among the $\,n\!+\!1\,$ values $\,a,f(a),f^2(a),\cdots, f^n(a)\,$ two must be congruent: for some $\,0\le i< j\le n\!:$ $\,f^j(a)\equiv f^i(a)\,$  so $f^{j-i}(a)\equiv a\,$ by: $ $ ($i$ times) apply $f^{-1}$ (to cancel $f^i)$.

This approach does not require solving the recurrence (in closed  form). Rather, we only need to prove that the function $f\:\!$  generating the recurrence is invertible. Then we may apply a fundamental fact - that the cycle graph of an invertible map on a finite set consists of purely periodic cycles, i.e. shape oh (o) vs. rho ($\rho$), i.e. no preperiod part as in the initial tail of the rho. This basic result is often overlooked, leading to unnecessarily complex proofs - which essentially amount to  reinventing the wheel (cycle). See here for further discussion and examples, including some nonlinear recurrences.
