about the complexity of recursive sequence If i have a recursive sequence $a_1=4$ and $a_{n}=a_{n-1}^{2}-2$ in $\mathbb{Z}_{M_{n}}$ where $M_n=2^n-1$

how i can calculate the complexity time of this sequence ? if we put it in the loop for n-1 iteration . 

pseudocode :

S=4;
i=2;

While($i&lt;n$,

$S=S^2-2 (\mod M_n)$

If( S==0  then Break[]);

);

im not sure that overall complexity is $O(log^3(M_n))$
I calculated the first few values of your sequence:
$$
4,2,2,2,2,2,2,2,2,\ldots
$$
Indeed, $a_2 = 4^2-2 \bmod{2^2-1} = 14 \bmod{3} = 2$, and henceforward we have $a_{n-1}^2-2 = 2^2-2 = 2$ and so $a_n = 2$.