I have a sequence defined as follows:$a_1 = A$$a_n = a_{n-1}^2 + B$$A, B$ are positive integers. I want to design an algorithm, which would calculate $N$-th term of this recurrence modulo $M$ for very big values of $N$, like $10^9$. If it was linear recursion, I would use matrix multiplication, but this time it won't work.
$N$-th term of a quadratic recurrence
algorithms;recurrence relation