I want to solve this difference equation: $H_{n+1}-(1+r^{2n+1})H_{n}=2-r^{2n+1}p_{n}$ Let $r>4$ be a positive integer. Let $p_{n}$ be the sequence of prime numbers with $n≥3$. I wante to solve this difference equation:
$$H_{n+1}-(r^{2n+1}+1)H_{n}=2-r^{2n+1}p_{n}$$ where $H_{n}$ is the unknown and $H_{3}=5$. I have no idea to start.

Notice you have
$$H_{n+1} = (r^{2n+1}+1) H_n + (2 - r^{2n+1 } p_n) $$
The first few terms are
$$ H_4 =  ( r^7 +1) H_3 + (2 - p_3r^{7} )$$
$$H_5 = ( r^9 +1)  H_4 + (2 - p_4 r^9 ) = ( r^9 +1)  ( r^7 +1)H_3 + ( r^9 +1)(2 - p_3r^{7} ) + (2 - p_4 r^9) $$
Thus if you iterate this you'll find
$$ H_n = H_3\prod_{k=3}^{n-1} ( r^{2k+1} +1) + \sum_{k=3}^{n-1}(2-r^{2k+1}p_k) \prod_{l=k}^{n-2} ( r^{2l+3} +1) $$
I have changed $n$ by $k$ in the indice of the prime number $p_n$ in the last equation.
